handling many redirects

Igor Sysoev is at rambler-co.ru
Sun Jan 6 23:12:52 MSK 2008


On Sun, Jan 06, 2008 at 09:00:47PM +0100, Manlio Perillo wrote:

> I need to migrate a site to a new URL scheme.
> Each page have a different url, and I want the old url to be still 
> accessible, but redirected (with a 301 HTTP status code) to the new url.
> 
> 
> With the rewrite module I can write (at server context):
> 
> rewrite  /old_url1  /new_url1/  permanent;
> rewrite  /old_url2  /new_url2/  permanent;
> ...
> 
> 
> The site does not have many pages, but is this efficient?

If you rewrite full URLs but not prefixes, then it's better to use map:

       map   $uri          $new {
             default       "";
             /old_url1     /new_url1/;
             /old_url2     /new_url2/;
             ...
       }

       server {

            location / {
                if ($new) {
                    rewrite  ^   $new  permanent;
                }

                ...
            }


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list