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've migrated my blog from DotClear2 to WP3.

I would like to add some URL rewriting on my NGinx configuration file, so that people who were following my blog using the RSS can still do the same without having to change the address in their aggregator.

The previous URL was: http://www.emidee.net/blog/index.php/feed/atom while the new one is: http://www.emidee.net/index.php/feed/atom

How could I write a rewrite rule in NGINX so that it automatically transfers to the new URL?

In short, I'd like to get rid of the /blog/ word in the URL.

Thanks!

share|improve this question
    
You should probably also remove that extra /index.php from your URLs. –  Michael Hampton Aug 24 '12 at 18:31
add comment

2 Answers

That should do the trick:

server {
  # more code ...
  location / {
    # more code ...
    location ~* ^/blog/([a-z0-9\.]+)$ {
      return 301 $scheme://$server_name$1;
    }
    # more code ...
  }
}
share|improve this answer
    
Thank you for your answer, but unfortunately I'm not redirected to emidee.net/index.php/feed/atom when I access emidee.net/blog/index.php/feed/atom Is there a way to debug what's going on under the hood? –  Mike Aug 24 '12 at 21:53
    
You can always activate debug logging, then nginx logs exactly what it's doing. But the rewrite rule you posted seems just fine. :) –  Fleshgrinder Aug 25 '12 at 4:48
add comment
up vote 0 down vote accepted

After some unsuccessful tries, this one seems to be working well

server {
    listen 80;
    server_name www.emidee.net emidee.net;
    root /var/www/http/emidee;

    include global.conf.d/restrictions.conf;
    include global.conf.d/wordpress.conf;

    rewrite ^/blog(.*)$ $scheme://$server_name$1 last;
}
share|improve this answer
add comment

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.