How to forward domain www.domain1.com to www.domain2.com with NS at Digital Ocean?

February 5, 2019 377 views
DigitalOcean DNS Ubuntu 18.04

Running wordpress Ubuntu, installed via Serverpilot (nginx reverse proxy apache)

I have 2 domains, domain1.com NS are with DO, domain2.com NS with another host, but pointing to DO servers. I need domain1.com to point to domain2,

I added both domains via serverpilot, so both domain1 & domain2 show the same exact website, and each domain can be used to access the site.

I think I may have set this up a little wonky, but I can’t figure out how to get domain1 to show domain 2 site.

Thanks in advance, and if I missed anything or my explanation doesn’t make any sense let me now.

Thank yoU!

3 Answers

Ok!

So if anyone else is having this problem it can be fixed real easy via editing the wp-config.php file

I did what @jarland had said, but it was causing all sorts of redirects. Serverpilot creates SPREQUESTURL for site url and home. So all I had to do was change that to the domain I wanted the website to show, domain1.com, and now both domain2.com and domain1.com both show domain1.com -

Hope it helps someone else!

Hey friend,

Given that your setup is Apache reverse proxied by Nginx, this may actually be quite easy. At least, I’m hoping it is. Try creating a “.htaccess” file in the document root for domain1 with this in it:

RewriteEngine ON
RewriteRule ^(.*)$ https://domain2.tld/$1 [R=301,L]

Replace “domain2.tld” with your domain, and adjust the https if you do not use SSL. If you already have a .htaccess there, rename it to something like “.htaccess.old” to keep it but get it out of the way.

Jarland

Thank you Jarland, so I think this is working, the problem I came across is that I am currently running wordpress, so there are some htaccess items listed already. I tried to add this to the current htaccess, it gave me an error with too many redirects. Then I created just this file and I think it worked, but I fear I may be missing some of the needed listed items in the htaccess file below? I tried to arrange some of them, but my knowledge on what the wordpress htaccess file is doing is a bit limited.

BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUEST
FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

END WordPress
Have another answer? Share your knowledge.