How to Redirect URLs using Nginx

By Tech-Assured     
May 5, 2021  2892 Views


If the need has arisen to redirect traffic from one URL to another, then you’ve come to the right place. We at Tech-Assured, provide network support as a part of our Server Management service.

Today we will show you how to Redirect URL’s using Nginx…


There are different types of Redirects but the common forms are Temporary & Permanent.

  • Temporary Redirects:
    This is really helpful, especially while performing maintenance in your company.
  • Permanent Redirects:
    This is helpful, when you have moved the content from your site and you don’t want your URL to access it anymore.


In Nginx, you can add following lines in the server configuration file:

For Temporary Redirects,

rewrite ^/oldlocation$ redirect

For Permanent Redirects,

rewrite ^/oldlocation$ permanent

Other Scenarios

In the document root directory of your site:



Note: /html if you have one site on the server.

/ if you have multiple sites on server

You can also create new file name html.conf or

Few examples

server { # Temporary redirect to an individual page rewrite ^/oldpage$ redirect; }

 server { # Permanent redirect to www server_name; rewrite ^/(.*)$$1 permanent; }
server { # Permanent redirect to new URL server_name; rewrite ^/(.*)$$1 permanent; } server { # Redirect to HTTPS listen      80; server_name; return      301$request_uri; }

Ask for help –
There are different commands for different types of Redirects, but our Support Engineers at tech assured have a solution for all server related issues.

Tech-Assured can help you deploy best IT practices and mitigate risks with a fully compliant IT framework.

Enlink Clients