# Redirect /olddir to /newdir

**URL:** <https://www.ruby-forum.com/t/redirect-olddir-to-newdir/202548>\
**Category:** NGINX\
**Created:** [February 1, 2011, 7:45am UTC](https://www.ruby-forum.com/t/redirect-olddir-to-newdir/202548 "2011-02-01T07:45:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 1, 2011, 7:45am UTC](https://www.ruby-forum.com/t/redirect-olddir-to-newdir/202548/1 "2011-02-01T07:45:41Z")

</div>

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/](http://domain.com/olddir/some/dir/) to  
[http://domain.com/newdir/some/dir/](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](http://domain.com/newdir$request_uri)? permanent;  
}

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

Thanks for your help.

Posted at Nginx Forum:

> **[Redirect /olddir to /newdir](https://forum.nginx.org/read.php?2,171236,171236#msg-171236)**
>
> 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/...

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [February 1, 2011, 7:48am UTC](https://www.ruby-forum.com/t/redirect-olddir-to-newdir/202548/2 "2011-02-01T07:48:12Z")

</div>

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

> location /olddir/ {  
> rewrite ^ [http://domain.com/newdir$request\_uri](http://domain.com/newdir$request_uri)? permanent;  
> }
> 
> The above rule does not work, it will redirect the user to  
> [http://domain.com/newdir/](http://domain.com/newdir/), instead of  
> [http://domain.com/newdir/some/dir/](http://domain.com/newdir/some/dir/).  
> If an user types the [http://domain.com/olddir/some/dir/](http://domain.com/olddir/some/dir/) url, nginx  
> should automatically redirect him/her to  
> [http://domain.com/newdir/some/dir/](http://domain.com/newdir/some/dir/). Right now, it brings the user to  
> [http://domain.com/newdir/](http://domain.com/newdir/).

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

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [February 1, 2011, 10:50pm UTC](https://www.ruby-forum.com/t/redirect-olddir-to-newdir/202548/3 "2011-02-01T22:50:40Z")

</div>

Thank you, Igor.

Posted at Nginx Forum:

> **[Re: Redirect /olddir to /newdir](https://forum.nginx.org/read.php?2,171236,171385#msg-171385)**
>
> 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/...
