Nginx rewrite urls

From wikinotes
Revision as of 21:50, 21 March 2021 by Will (talk | contribs) (Created page with "Nginx can rewrite requested URLs (not domains) using rules.<br> It does so using simple PCRE regex expressions. = Examples = <blockquote> <source lang="bash"> location / {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Nginx can rewrite requested URLs (not domains) using rules.
It does so using simple PCRE regex expressions.

Examples

location / {
  # redirect /nginx-tutorial? to /somePage.html
  rewrite ^/nginx-tutorial?$ /somePage.html break;
  
  # strip /path/ from URL, but keep everything else
  rewrite ^/path/(.*)$  /$1 break;

  # entirely replace url
  rewrite ^ https://app1.company.com/app1/;

}