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

I'd like to make a 301 rewrite to the sites's index without any querystring. Like this:

http://example.com/anypage.asp?anyvar=anyvalue

To:

http://example.com/

Here's a real example:

http://atipico.com.br/conteudo.asp?P_categ=23

I am trying to follow this: http://wiki.nginx.org/NginxHttpRewriteModule#rewrite

(The commented are my attempts):

location ~ /conteudo\.asp(.*)$ {
    #rewrite ^ / permanent;
    #rewrite ^ /? permanent;
    #return 301 /;
    #return 301 /?;
    #if ($args) { return 301 /; }
}

It always rewrites to http://atipico.com.br/?P_categ=23

Any ideas?

share|improve this question
1  
Did you try rewrite ^/conteudo.asp$ /? permanent; (i.e. without the location block) - seems to work fine for me (even without the start/end delimiters, and without the question mark) –  cyberx86 Oct 19 '11 at 18:31
    
It looks fine, but why do you extract the GET parameters into a variable which you then don't use? Not sure how it behaves in this situation then. –  faker Oct 19 '11 at 19:10
1  
rewrite ^ /? permanent; works fine. Did you clear browser cache or try with another web browser? –  quanta Oct 20 '11 at 0:07

1 Answer 1

This is the best rule I found and it is working to me:

rewrite ^/content /? permanent;

Meaning, rewrite all requests:

  • starting in the root of the domain (^/)

  • than followed by "content"

  • to the root (index) of the site (/)

  • removing all query strings it might have (?)

  • and show a 301 redirect in the headers.

I guess that's it.

share|improve this answer
    
Adding as a reference for OP: wiki.nginx.org/HttpRewriteModule#rewrite It will explain more details about the ? notation which drops the arguments. –  Grumpy Dec 19 '12 at 12:35
    
It works! Thanks! –  Tyler Long Mar 13 '13 at 14:26

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.