Create Temporary and Permanent Redirects with Nginx

The difference between permanent redirect, and temporary redirect in nginx is defined by the following tags :

  • redirect #for a temporary redirect
  • permanent #for a permanent redirect

 

Temporary redirect :

rewrite ^/old-location$ http://www.your-domain.com/new-location redirect;

Permanent redirect :

rewrite ^/old-location$ http://www.your-domain.com/new-location permanent;

Redirect samples :

# 1. Redirect from old location, to new domain
rewrite ^/old-location$ http://www.your-domain.com/new-location redirect;

# 2. Redirect from old location, to a new location on the same domain
rewrite ^/old-location$ /new-location redirect;

# 3. Change slug format
rewrite ^/something-old/(.*)$ /something-new/$1 redirect;

 

Top