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 have the following line in nginx:

try_files $uri $uri/ /index.html;

As far as I understand, it rewrites all queries to files that are not found to index.html. Meaning, that index.html?foo=bar and idontexist.html?foo=bar leave the same result which screws up Google crawling.

How can I not rewrite but redirect to the default url?

The perfect solution would be even without the index.html. So http://domain.com/idontexist.html?foo=bar would redirect using 301 to http://domain.com/?foo=bar

share|improve this question

2 Answers 2

location / {
    try_files $uri $uri/ @to_home;

location @to_home {
    return 301 /$is_args$args;
share|improve this answer
up vote 0 down vote accepted

I've shortened VBart's code snippet above. It works as it should:

try_files $uri $uri/ / =301;
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.