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$ http://www.redirectlyapp.com/n... permanent;”
- The “rewrite” matches regular expression patterns in parenthesis.
- The “/old.html” provides the original location of the page
- The “http://www.domain.com/new.html” 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.