0

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?

2 Answers 2

1

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 '';
    ....
Sign up to request clarification or add additional context in comments.

Comments

0

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

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.