Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am redirecting /example.php?var=value to /index.htm like this:

rewrite /example.php?var=value / permanent;

However, the browser ins printing the final uri like this:

domain.com/?var=value

How can I have a clean uri like this?

domain.com

Thanks.

share|improve this question

3 Answers 3

Excerpt from nginx rewrite module documentation:

If in the line of replacement arguments are indicated, then the rest of the request arguments are appended to them. To avoid having them appended, place a question mark as the last character:

rewrite  ^/users/(.*)$  /show?user=$1?  last;
share|improve this answer
    
Thanks, @AlexD! So in my case how could I redirect domain.com/example.php?var=anyvalue to /index.htm? I am trying rewrite /example.php?(.*) /? last; or rewrite /example.php?(.*) /? permanent; but it is not working, it continues redirecting to /index.htm?var=anyvalue –  Roger Oct 18 '11 at 15:40

Put a question mask at the end of replacement:

    location ~ \.php$ {
        location ~ /example\.php$ {
            if ($args ~ var=value) {
                rewrite ^ /? permanent;
            }
        }
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi.conf;

        fastcgi_intercept_errors        on;
        error_page 404 /error/404.php;
    }
share|improve this answer
    
Thanks, @quanta! Shouldn't there be any other way to do this without using "if"? –  Roger Oct 18 '11 at 15:41
    
No need to worry. Only rewrite in if condition is 100% safe. –  quanta Oct 18 '11 at 15:49

The simpliest way I found is this:

rewrite ^/example.php /? permanent;

Thanks for all.

share|improve this answer

Your Answer

 
discard

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.