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 recently moved my blog from using WordPress over to using Jekyll (I like the idea of static files for my blog). I'm using Nginx (was using it with PHP-FPM before) and have things setup to handle stuff. I've encountered one problem I do not know how to fix.

The URL structure I'm using is

/atthekeyboard/YYYY/MM/DD/title-of-post 

I have about 5 years worth of blog posts that have been indexed by Google and they are

/attheykeyboard/YYYY/MM/DD/title-of-post/

I want to rewrite all the older calls with the trailing slash to use the non-trailing slash URL until Google indexes all the new stuff.

Here is the nginx config stuff I have already:

    location /atthekeyboard {
            index index.html;
            try_files $uri.html $uri/ /notfound.html;
    }

I'm using try_files because the posts are actually saved as title-of-post.html and I didn't want the .html part.

Thanks in advance for your advice and solutions!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Something like this should remove the trailing slash and then let Nginx reparse the location blocks.

location ~ ^(/atthekeyboard/.+)/$ {
    set $noslash $1;
    rewrite ^ $noslash permanent;
}
share|improve this answer
    
I added that in and I get '[emerg]: unknown "noslash" variable' when I run nginx -t –  GrumpyCanuck Feb 28 '11 at 14:38
    
@GrumpyCanuck Edited it, should be compatible with older nginx versions now. –  Martin Fjordvald Feb 28 '11 at 21:37
    
sorry, still not working :( Here's a paste of the configuration file I had to add a $ to noslash in the set command in order to get nginx to stop complaining. In case it matters, I'm using nginx version 0.7.67 –  GrumpyCanuck Feb 28 '11 at 23:36
    
@GrumpyCanuck it was me being stupid, the configuration actually does work but I had forgotten the permanent flag on rewrite so it did an internal redirect instead of an external one. So while it redirected you couldn't actually see it. –  Martin Fjordvald Mar 1 '11 at 7:29
    
It works perfectly now, thanks so much Martin! –  GrumpyCanuck Mar 1 '11 at 13:58

i think the HTTPRewriteModule is what you are looking for

share|improve this answer
    
Duh, I should've mentioned that I do know about the HTTPRewriteModule but I have been unable to figure out the proper rewrite rule to make it happen. –  GrumpyCanuck Feb 28 '11 at 2:45

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.