How to redirect an old domain to the new using Nginx


Example: you want to change old domain (tutorialspots.com) to the new (tutorialspots.net). There are some reasons e.x your domain is banned by Google.

Edit your .conf file e.x: /usr/local/nginx/conf/conf.d/tutorialspots.com.conf

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.com www.tutorialspots.com;
    rewrite ^ http://tutorialspots.net$request_uri? permanent;
}

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.net www.tutorialspots.net;
    # rest of your .conf
}

redirect-an-old-domain-to-the-new-using-nginx

or

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.com www.tutorialspots.com;
    rewrite ^(.*) http://tutorialspots.com$1 permanent;
}

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.net www.tutorialspots.net;
    # rest of your .conf
}

or

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.com www.tutorialspots.com;
    return 301 http://tutorialspots.org$request_uri;
}

server {
	listen 68.235.32.101:80;
    server_name tutorialspots.net www.tutorialspots.net;
    # rest of your .conf
}

For SSL and non-SSL

server {
	listen 68.235.32.101:80;
    listen 68.235.32.101:443;
    server_name tutorialspots.com www.tutorialspots.com;
    rewrite ^ $scheme://tutorialspots.net$request_uri? permanent;
}

server {
	listen 68.235.32.101:80;
    listen 68.235.32.101:443;
    server_name tutorialspots.net www.tutorialspots.net;
    # rest of your .conf
}

Leave a Reply