realer
By:
realer

Redirect from french domain to english domain

March 15, 2015 1.1k views
Nginx DNS CentOS

I have two domains - lets call them engsite.com and frenchsite.com - running on a Nginx server.

When users visit frenchsite.com, I want them to be redirected to engsite.com/index_french.html

A /cname records? Or nginx redirects? Not sure how best to achieve this.

1 Answer

This would be done by entering a server listener in Nginx, redirecting the domain on the server. You need to have a DNS A-record point to the same Nginx web-server's IP-adress, as you normally would if frenchsite.com was in use. Then add this to the config:

server {
        server_name frenchsite.com;
        return 301 $scheme://www.engsite.com/index_french.html;
}

HTML status code 301 tells Nginx that the page/site has moved, and redirects the user to the given URL. If you would want to replicate everything that the user has written after the domain name, for instance http://frenchsite.com/news.html, using the "/news.html"-part in the new redirected URL, use it like this:

server {
        server_name frenchsite.com;
        return 301 $scheme://www.engsite.com$request_uri;
}
Have another answer? Share your knowledge.