How to Redirect on Nginx Server
This will cover instructions on how to create a Redirect on Nginx. The following steps will require ownership or control of the site your TinyURL points to. As these changes may lead to an interruption of service for your website, if you don't have or you are unsure how to proceed, please consult with your IT, hosting provider or Web Development team.
Nginx Server
Redirection on Nginx can we accomplish using many ways, but the most common way to redirect by creating the server block using the return Directive.
-
Log on to your Dedicated Nginx server using Administrator account/access.
-
Create a file named the 'redirects.conf' file in your '/nginx.example.com' directory.
-
On your 'redirects.conf' file, add the contents below to to create a redirect:
To redirect a specific page :
if ($request_filename ~ oldfile.html){ rewrite ^ http://example.com/newfile.html? permanent; }
To redirect an entire site :
if ($request_filename ~ /*){ rewrite ^ http://example.com? permanent; }
Note : Remember to substitute and validate that you have the correct html file names and domain names on these instructions:
* '*oldfile*' : This is the html file for your old page
* '*newfile*' : This is the html file for your new page
* '*example.com*' : This is the root web folder of the new site
- For the changes to take effect, after you insert these commands to your 'redirects.conf' file, Reload Nginx by running the command
[server]$ sudo /etc/init.d/nginx reload
. If you're on a VPS (private server), click on the Restart button of your server.