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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
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;
}
Submit an Answer