Question

Redirecting multiple domains to one domain

I have three domains. Domain 1, 2 and 3.

I want to redirect domain 2 and 3 to go to domain 1.

I have a droplet setup, and everything works fine for domain one. Site loads.

Current setup to redirect domain 2 and 3 to one:

DNS Two A records for each, pointing to the domain 1 droplet. A record with WWW and one without.

NGINX Setup:

server {
    listen 80;
    server_name www.domain3.com domain3.com;
    return 301 https://www.domain1.com$request_uri;
}

server {
    listen 80;
    server_name www.domain2.com domain2.com;
    return 301 https://www.domain1.com$request_uri;
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain1.com;
    root /home/forge/domain1.com/public;

It seems to be working for me. For others, it’s not working when links are sent to them. Sometimes it works if they re-type it in their browser. Eventually, after a while, they seem to all work though. A few times I’ve noticed it loads the site, but isn’t changing the URL.

Is this just taking time to propagate? Or is this setup incorrect but works in some cases.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @nmarketti,

It sounds like that it might be due to browser cache.

What happens if you try with curl for example? So it would look something like this:

  1. curl -IL http://domain2.com

Let me know how it goes. Regards, Bobby