Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'd like to make a 301 rewrite to the sites's index without any querystring. Like this:


Here's a real example:

I am trying to follow this:

(The commented are my attempts):

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

It always rewrites to

Any ideas?

share|improve this question
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
rewrite ^ /? permanent; works fine. Did you clear browser cache or try with another web browser? – quanta Oct 20 '11 at 0:07

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: 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


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.