Redirect /olddir to /newdir

Hi all,

I need your suggestions to create a rewrite rule in nginx that will
redirect the user from an old dir to the new one:
http://domain.com/olddir/some/dir/ to
http://domain.com/newdir/some/dir/

location /newdir/ {
try_files $uri $uri/ /newdir/index.php?$uri&$args;
}
location /olddir/ {
rewrite ^ http://domain.com/newdir$request_uri? permanent;
}

The above rule does not work, it will redirect the user to
http://domain.com/newdir/, instead of
http://domain.com/newdir/some/dir/.
If an user types the http://domain.com/olddir/some/dir/ url, nginx
should automatically redirect him/her to
http://domain.com/newdir/some/dir/. Right now, it brings the user to
http://domain.com/newdir/.

Thanks for your help.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,171236,171236#msg-171236

On Tue, Feb 01, 2011 at 01:44:13AM -0500, TECK wrote:

location /olddir/ {
rewrite ^ http://domain.com/newdir$request_uri? permanent;
}

The above rule does not work, it will redirect the user to
http://domain.com/newdir/, instead of
http://domain.com/newdir/some/dir/.
If an user types the http://domain.com/olddir/some/dir/ url, nginx
should automatically redirect him/her to
http://domain.com/newdir/some/dir/. Right now, it brings the user to
http://domain.com/newdir/.

location /olddir/ {
rewrite ^/olddir/(.*)$ http://domain.com/newdir/$1 permanent;
}


Igor S.
http://sysoev.ru/en/

Thank you, Igor.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,171236,171385#msg-171385

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs