.htaccess file making new domain redirect to my original domain

35 views Asked by At

To give a little background that may help understand this. I only had one domain on my host's server initially. I just added a new domain and it was redirecting to my first site.

I had to create an .htaccess file redirect my first site so that it would have my SSL on every page and so that it took the www. away from the sites name. The www. was causing issues with sessions when a customer would login.

So my code was like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

The tech support of my host company said that this line was making my new site redirect to my old site:

RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]

How can I make my code work so that is still has the exact same functionality of what it was doing and not interfere with my new domain and make it re-route to my old site?

1

There are 1 answers

4
Panama Jack On BEST ANSWER

Why not just exclude the new site, if I am understanding correctly?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?newsite\.com [NC]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com [NC]
RewriteRule ^(.*)$ https://oldsite.com/$1 [R=301,NE,L]
RewriteCond %{HTTPS} ^off
RewriteCond %{HTTP_HOST} !^(www\.)?newsite\.com [NC]
RewriteRule ^(.*) https://oldsite.com/$1 [R=301,NE,L]

Alternatively maybe you can just tell it to not do anything based on the host. Try putting this at the top of your rules.

RewriteCond %{HTTP_HOST} ^(www\.)?newsite\.com [NC]
RewriteRule ^ - [L]

Note I haven't tested this.