Redirecting WordPress Permalinks in Nginx

Posted by on Sat, January 19, 2013

▼ A d v e r t i s e m e n t

I know, it’s been really a long time since I last wrote an article in this blog. But trust me, I’ve done a lot of improvements at the back end. The blog is now in a new server, with new backup infrastructure, and most importantly served by Nginx.

I was just casually looking at 404 errors in my Awstats and saw a bunch of these:

romantika.name-404-errors

I’ve changed the permalink structure for this site ages ago, and I did not notice this. I have no excuse for this mistake.

To avoid more 404 I made a simple fix in my Nginx configuration:

rewrite "/v2/\d{4}/\d{2}/\d{2}/(.*)" /v2/$1 permanent;

So now if visitors try to access http://www.romantika.name/v2/2007/05/02/wordpress-plugin-random-posts-widget/ they will be redirected to the new permalink http://www.romantika.name/v2/wordpress-plugin-random-posts-widget/

That’s it. I love Nginx for its simplicity and speed. I should thank my friends Welly and Englebert for promoting Nginx to me.

I love challenges using Regex so if you have any questions do leave a comment. Can’t guarantee in what year I will be able to respond though!

Related Posts with Thumbnails

Tags:

Facebook Comment

WARNING & REMINDER: Comments are moderated and there is no exception. Comments unrelated to the post, too short, using phoney emails or funny names, will be marked as spam. Foul languages are filtered as spam. Your email will never be displayed on this site. If you would like to receive replies, use a valid email address and check the subscription box below.
 

Comments are closed.