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