Uploaded on Mar 8, 2023
You need to redirect old URLs when you change website domain. Here's how to redirect location to another domain in NGINX.#nginx #web development Visit https://ubiq.co/tech-blog/how-to-redirect-location-to-another-domain-in-nginx/
How to Redirect Location to Another Domain in NGINX
How to Redirect Location to
Another Domain in NGINX
Open NGINX configuration file
If you are using NGINX’s main configuration file nginx.conf, without virtual hosts, then
run the following command
$ sudo vi /etc/nginx/nginx.conf
If you have configured separate virtual hosts for your website (e.g www.mysite.com),
such as /etc/nginx/sites-enabled/mysite.conf then open it with the following command
$ sudo vi /etc/nginx/sites-enabled/mysite.conf
Redirect Location to Another Domain
Let’s say you want to redirect /product to new domain (www.newsite.com), then add the following
location block inside your server block
server{
...
location /product {
rewrite ^/product(.*)$ https://www.newsite.com/$1 redirect;
}
...
}
Restart NGINX
Run the following command to check syntax of your updated config file.
$ sudo nginx -t
If there are no errors, run the following command to restart NGINX server.
$ sudo service nginx reload #debian/ubuntu
$ systemctl restart nginx #redhat/centos
Thank You
Visit for details
https://ubiq.co/tech-blog/how-to-redire
ct-location-to-another-domain-in-nginx/
Comments