How to Alias URL to Another in NGINX


alias url to another in nginx

If you move your web page, then you can add an alias to your old URL so that when users load it, your website displays content from the new page, without changing the URL in browsers’ address bar. Let us take a look at how to alias URL to another in NGINX.

 

How to Alias URL to Another in NGINX

Here are the steps to alias URL to another in NGINX.

 

1. Open NGINX config file

Open NGINX config file in a text editor. You will typically find it at /etc/nginx/nginx.conf


$ sudo vim /etc/nginx/nginx.conf

 

2. Alias URL to Another

Let’s say you want to alias a directory /product to /new-product, then simply use the Alias directive.


server {
 server_name example.com;
  root /path/to/root;
  location / {
   # your config here
  }
  location /product/ {
   alias /new-product/;
  }
}

 

The above code will alias one directory to another. If you want to alias just a single URL, then use the rewrite directive.


location /product-page {
  redirect /new-product-page;
}

 

3. Reload NGINX web server

Reload NGINX server to apply changes.

$ sudo service nginx reload

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!