1

I am currently redirecting my root domain to a subfolder. However I want to exclude a query string url which is used for an ajax call (www.example.com/?act=12). I am however unsure of how to do this in nginx.

This is my current nginx config file

server {
        listen          80;
        server_name     example.com;
        return 301      http://www.example.com$request_uri;

}

server {
        listen 80;
        server_name www.example.com;
        root /var/www/example.com/public;

        index index.php index.html;

        location = / {
                return 301 http://www.example.com/it/;
        }

        location / {
                proxy_pass http://localhost:8080;
                include /etc/nginx/proxy_params;
        }

        location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
                expires 30d;
        }

        location ~ /\.ht {
        deny  all;
    }
}

Any help will be appreciated.

1 Answer 1

2

That can be achieved by using the evil if block.

The query string arguments are presented as variables with a $arg_ prefix. If you just need to test that act is set, try this:

location = / {
    if ($arg_act) {
        rewrite ^ /my/ajax/call last;
    }
    return 301 http://www.example.com/it/;
}

If you need to test for a specific value of $arg_act use the = operator.

See this document for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.