HTTP redirection is a way to point one domain or address to another. There are a few different kinds of redirects, each of which means something different to the client browser. The two most common types are temporary redirects and permanent redirects. In this article, we will explore how to implement each of these redirects in Nginx.
Temporary redirects are useful if a URL temporarily needs to be served from a different location. For example, if you are performing site maintenance, you may wish to use a temporary redirect of from your domain to an explanation page to inform your visitors that you will be back shortly.
You can create a temporary redirect in Nginx by adding a line like this to the custom nginx.conf in the /public_html/ directory:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation redirect;
Permanent redirects inform the browser that it should forget the old address completely and not attempt to access it anymore. These are useful when your content has been permanently moved to a new location, like when you change domain names.
Likewise, You can create a temporary redirect in Nginx by adding a line like this to the custom nginx.conf in the /public_html/ directory:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation permanent;