Creating redirects with Nginx

Follow these steps to create your redirects:

  1. View the configuration file location article to create your local /nginx/ directory.
  2. Create a file named redirects.conf in this /nginx/ directory.
  3. Add the contents from the following sections.
  4. Make sure to reload Nginx for the changes to take effect.

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 non-secure traffic to HTTPS

if ($server_port = 80) {
	rewrite ^/(.*)$$1 permanent;

See also

Did this article answer your questions?

Article last updated .