Site icon GetPageSpeed

Remove query parameters in Nginx

Sometimes you want to make Nginx ignore a parameter passed in page request.

Here is a short snippet to do that:

if ($query_string ~ "^(.*)gclid=(.*)$") {
    rewrite ^(.*)$ $uri? permanent;
}

This comes useful in case you run a Magento store with some SEO plugins that redirect to base URL of every page, but want the specific parameter (gclid in this case) to be retained, for integration with Javascript code (Google Analytics).

Exit mobile version