Question

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

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!


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.

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 SP_REQUEST_URL 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!

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 %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

END WordPress

jarland
DigitalOcean Employee
DigitalOcean Employee badge
February 5, 2019

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel