Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

example.com/series/

example.com/series/some-stuff/

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:

example.com/series/ --> This one is correct by default.

example.com/series/some-stuff.html --> 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;

example.com/series/ redirects to example.com/series/index --> 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.

example.com/some-stuff.html redirects to example.com/series/some-stuff --> Correct!

example.com/series/some-stuff/ redirects to example.com/series/some-stuff --> 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 (example.com/series/index) but keep the others as they are after the rewrite. Thanks!

edit:

I tried to make a rewrite just for example.com/series/index 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

1 Answer 1

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 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 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 at 21:25

Your Answer

 
discard

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.