Redirecting with NGINX

September 1, 2015 | Posted in NGINX

How do you redirect a URL, say /shop to another URL, say /product within your website? You add a redirect in location.

    location /shop/ {
      rewrite ^/shop/(.*)$ /product/$1 permanent;
}

This location redirect does the following:

  1. It catches URLs beginning with /shop/
  2. It redirects /shop/[whatever] it to /product/[whatever]
  3. Sends a 301 permanent redirect

So it will redirect /shop/ABCDEF and /shop/ABCDEF/ to /product/ABCDEF and /product/ABCDEF/ respectively.

Related Posts

27 Feb 2017 » Provisioning an ubuntu server for Django, Postgres, NGINX

24 Jan 2017 » Stats from NGINX logs using Goaccess