Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

i want to redirect them to other urls like:

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

share|improve this question

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.

share|improve this answer
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. – Tronic Nov 23 '12 at 20:08

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" ); 

share|improve this answer

Your Answer


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.