< 1 min read
website A
would be served by its web servers, returning the requested content. However, when a redirect service is in place, the webserver must first check the existence of query parameters in the requested URL. If no query parameters exist, the request gets processed as normal. If query parameters are present, a redirect response is immediately returned pointing to the same requested URL but with the query parameters removed. This redirect response will instruct the browser to request the page again, this time using a clean URL that will not trigger the conditions for local storage deletion.
The following diagram describes the journey of a request subjected to the redirect service, i.e. one with query parameters:
server { listen 80; server_name localhost; # enables nginx to sit behind a reverse proxy absolute_redirect off; # only redirect if query parameters exist in the request if ($is_args) { # redirect to the requested URI (no query parameters) return 301 $uri; } location / { root /usr/share/nginx/html; index index.html index.htm; } }The nginx configuration above contains the minimum necessary to implement the redirect service (and was tested using nginx version 1.17.4). There are three notable points relating to this configuration: 1. Turning off absolute_redirect allows you to run this configuration where the protocol and port number of nginx does not match one of the external services e.g. reverse proxies, containers, etc. It would mean the location in the redirect response will be relative to the current page. 2. The absolute_redirect and if condition for query parameters can be restricted to a single location section in nginx (rather than for the entire server section) 3. The absolute_redirect directive has been available since version 1.11.8.
docker run -ti --rm -p 8080:80 -v $PWD/default.conf:/etc/nginx/conf.d/default.conf nginxIf you then access http://localhost:8080?param1=value1 in your browser, you will be automatically redirect to http://localhost:8080/.
Manage preferences
© Permutive 2025. All rights reserved.
All rights reserved.