Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing a migration from a WordPress blog to a Jekyll Blog using NGINX as my HTTP server and I don't want to break the Internet by leaving some URL's not working as expected. I got to a point where I really need to ask for help.

The original WordPress blog URLs are like this:

I want to mimic this urls by removing the file extension (.html) and respond with a non 404 page if someone has stored the WordPress URLs in his bookmarks. The Jekyll default URLs without any rewrites are like this: --> This one is correct by default. --> Not ok.

As you can see the first URL, series section its already ok because it's the index.html page and Jekyll hides de file name in that case (as expected), but when you access any other page in the same section (/series) you get the full file name with extension. Ok, so, I started working in the rewrites to remove the extension and be able to respond to the same wordpress URL and got here:

rewrite ^/series/(.*)\.html*$ /series/$1 permanent;
rewrite ^/series/(.*)/$ /series/$1 permanent; redirects to --> It's working ok but I don't like that now it's showing me the file name (index).

The other ones are working as I expect and are responding to the old WordPress URls. redirects to --> Correct! redirects to --> Correct!

As you can see I've manage to make this URLs work but with the exception of adding the file name (index) to the main series page. All I want is to do is fix the URL that I "broke" with the rewrites ( but keep the others as they are after the rewrite. Thanks!


I tried to make a rewrite just for doing this:

rewrite ^/(series/index.html$|series/index$) /series/ permanent;

But it didn't worked all I get is 404s.

I also tried to do a location + alias for that URL and got a 404 also.

share|improve this question
up vote 1 down vote accepted

The question is very poorly formatted, with obvious mistakes in content, inconsistencies between the lines, and omission of other relevant rewrite rules to shed the light onto the complete and full picture, so, I'm not sure a correct answer could be provided.

However, the general idea is that there is a difference between permanent and redirect rewrites on the one hand, which rewrite the URL as visible to the user, and internal rewrites that rewrite the URL within the server itself, on the other.

So, what you really want here is an internal rewrite of the user-visible URL back to what it actually is internally. Maybe something like this, and remove any other rewrites for /series/index:

rewrite ^/series/$ /series/index last;
if ($request_uri = /series/index) {  return 301 /series/;  }
share|improve this answer
Hi, I'm sorry for not explaining my self better, I thought being brief was going to make it easier to understand, but I was wrong. I've fix the question to be more explicit. About your answer, does this rewrite with IF statement is going to be inside a location? if not, why are we using an IF statement if they are evil? – albertogg Jan 22 '14 at 20:18
You'd put these in the same place where the rest of your rewrite rules are; how could I possibly know where exactly do you need to put it, if you haven't provided anything other than your rewrite rules? :-) Also, please re-read the IfIsEvil note, the very top of it clearly states that return is always 100% safe. – cnst Jan 22 '14 at 20:50
Yes, your rewrite rules are working as expected, thanks a lot, you are right up from the start. Sorry again for not being completely explicit. Thanks <3. – albertogg Jan 22 '14 at 21:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.