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.

  1. Log on to your Dedicated Nginx server using Administrator account/access.

  2. Create a file named the 'redirects.conf' file in your '/' directory.

  3. 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 ^ permanent; }

    To redirect an entire site :

    if ($request_filename ~ /*){ rewrite ^ 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
*  '**'  : This is the root web folder of the new site
  1. 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.
Last updated on 8th January 2021

Please enter a valid email address.

Signup for a TinyURL premium account

Unlock access to full analytics to your TinyURLs, use your own branded domain, and more.

View Details

Create an Account

Create an account to enjoy easy link shortening, customized TinyURLs, and full shortened URL history.

Sign Up