3

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?

4
  • 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, 2011 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, 2011 at 19:10
  • 2
    rewrite ^ /? permanent; works fine. Did you clear browser cache or try with another web browser?
    – quanta
    Oct 20, 2011 at 0:07
  • Yes I had to clear browser cache for updates to have effect, didn't think this would be the case but tried it after reading @quanta comment and fixed my issue
    – 00-BBB
    Jan 28, 2019 at 16:19

1 Answer 1

6

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .