Barry Mockett
Barry Mockett

Reputation: 11

Nginx query parameters

I have nginx hosting some static content

location /help/ {

    default_type text/html;
    alias /etc/nginx/html/help;
    index index.html;
    }

And that works fine if a request is made

e.g. http://www.blah.com/help

It loads the default page and works without issue.

However if I request http://www.blah.com/help/?_ga=xxxxxxxx.....

The query parameters get requested and return a 404.

So really my query is can I make this request and "ignore" the query parameters or will I need to consider an alternate method -

e.g Proxy pass and a URL rewrite?

Upvotes: 0

Views: 2895

Answers (2)

miknik
miknik

Reputation: 5951

An if condition evaluation requiring regex comparison adds unnecessary processing time to the request.

A rewrite then adds another regex capture and triggers a new evaluation of the rewritten uri, more unnecessary overhead.

It's actually really easy to drop a query string. It's stored in the $args variable, so just clear that:

location /help/ {
    set $args '';
    ....

Upvotes: 1

Barry Mockett
Barry Mockett

Reputation: 11

Ok So I solved this one myself after a long old search.

 location /help {
             if ($args ~* "_ga="){
              rewrite ^(.*)$ $uri? permanent;
              }
             default_type text/html;
             alias /etc/nginx/html/help;
             index index.html;
             }

In case anyone has the same problem

Upvotes: 0

Related Questions