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:

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.

edited by MattIPv4

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.

Submit an Answer
1 answer

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:

  • curl -IL http://domain2.com

Let me know how it goes.

  • Hey @bobbyiliev -

    I think you might be right. I ran that through terminal and it’s showing a 301 Moved Permanently…with the details.

    I ran: curl -IL domain2.com and it returned below:

    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.17.3
    Date: Sun, 19 Apr 2020 00:24:55 GMT
    Content-Type: text/html
    Content-Length: 169
    Connection: keep-alive
    Location: https://domain1.com

    HTTP/2 301
    server: nginx/1.17.3
    date: Sun, 19 Apr 2020 00:24:55 GMT
    content-type: text/html
    content-length: 169
    location: https://domain1.com

    HTTP/2 200
    server: nginx/1.17.3
    date: Sun, 19 Apr 2020 00:24:55 GMT
    content-type: text/html; charset=UTF-8
    vary: Accept-Encoding
    link: https://domain1.com/wp-json/; rel=“https://api.w.org/
    link: https://domain1.com/; rel=shortlink
    x-frame-options: SAMEORIGIN
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff

    To be honest I’ve never had to forward multiple other domains like this so I’m assuming what returned is correct. Small learning curve for me here!

    • Hi there @nmarketti,

      Yes, indeed this looks correct. What you could try is clearing your browser’s cache and then testing it again. Note that if you are using Chrome it tends to cache such redirects pretty hard.

      Let me know if you have any other questions.