How to add 301 redirects to Nginx using server level configuration

Right decorative Article tab

Jul 20th 2020

In Nginx, you can accomplish most redirects with the built-in rewrite directive. This directive is available by default on a fresh NGINX installation and can be used to create both temporary (302) and permanent (301) redirects. In its simplest form, it takes at least two arguments: the old URL and the new URL.

You can create a permanent redirect in NGINX by adding a line like this to the server block entry in the server configuration file (we advise these sit near, if not at the bottom of the file):

“rewrite ^/old.html$ permanent;”

  • The “rewrite” matches regular expression patterns in parenthesis.
  • The “/old.html” provides the original location of the page
  • The “” is the new URL of the page and is where the server should redirect visitors to.

The “permanent” tells NGINX that this is a permanent redirect so it’ll use the 301 (moved permanently) response code. Alternatively, you can use “redirect” instead of “permanent” and it would use the 302 (found) response code.

However, to save time and potential human error, Redirectly makes it easier for NGINX users to create redirect lists by auto-matching URLs that haven’t changed, and leaving those that do not match for the user to drag and drop on to the new URL with ease.

After creating a new list of URLs to redirect, it’s then possible to export the list specifically for NGINX to then copy and paste the new redirect entries into the server configuration file. After this step, you need to restart/reload NGINX for the redirects to start working as expected.

Find out more about Redirectly’s features with auto-crawl, auto-match, bulk matching and multi-tech export.

Left decorative tab Left decorative tab Left decorative tab Right decorative tab Right decorative tab
Let’s get started

Save time. Be one of the first to use Redirectly.

Join our waiting list to get early access to our BETA and immediate access to our demo playground.

Please correct the following error(s):

  • ${ error }
Thank you for joining the waiting list for access to Redirectly’s BETA.

We’re working hard to put Redirectly into the hands of developers and SEO strategists all over the world and will have you on board as soon as we can. We'll be in touch soon!

In the meantime please feel free to visit our demo playground. Visit to access.