0

i have to permament redirect some old urls in nginx. the old urls are old-style php urls including a parameter for loading content. they look like this:

http://www.foo.com/index.php?site=foo http://www.foo.com/index.php?site=bar 

i want to redirect them to other urls like:

http://www.foo.com/news http://www.foo.com/gallery 

any advice on how i can achieve this? my tries failed. thanks in advance!

2 Answers 2

1

If you have a direct mapping between old URL parameters and new URL path, you could use such a syntax :

location /index.php { ... try_files $uri /$arg_site =404; } 

With such a config, any request starting with/index.php will first be tried againt the exact URL, then if there's no matching file or location, nginx will try an internal redirect with /foo if the original URL is /index.php?site=foo. If that fails too, nginx will send a 404 HTTP Not Found response.

The variable $arg_site is set to the value of the URL parameter site.

1
  • okay thanks. actually the old and the new urls aren't the same. so e.g. index.php?site=foo AND index.php=site=bar should redirect to /home. Commented Nov 23, 2012 at 20:08
0

i fixed this issue by using php and not the nginx rewrite functionality:

if (isset($_GET["site"]) { switch ($_GET["site"]) { case 'foo': Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: /foo" ); break; ... } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.