Creating redirects with Nginx


To redirect a URL in a website running on an Nginx server, you must manually create a redirects.conf file. In this file will then add your redirect code.

Steps to create a redirect on an Nginx server

  1. View the configuration file location article to create your local /nginx/ directory.
  2. Create a file named redirects.conf in this /nginx/ directory. You can create this via SSH or FTP.
  3. Add one of the contents from the following sections. Make sure to change the domain name to your actual domain. 
  4. If you're on a Dedicated Serverreload Nginx for the changes to take effect. If you're on a VPS (private server), restart your server in the panel. You can do this on the VPS page by clicking the Restart button to the right of your server.

Redirecting a single file

if ($request_filename ~ oldfile.html){
	rewrite ^ permanent;
This redirects requests from to

Redirecting an entire site

if ($request_filename ~ /*){
        rewrite ^ permanent;
This redirects requests to your site to Change to any site you'd like to redirect to.

Redirecting your site from HTTP to HTTPS

View the following article for instructions on how to redirect your Nginx site from HTTP to HTTPS.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?