0
votes

Currently I have

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

RewriteCond %{HTTP_HOST} ^domain2\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

RewriteCond %{HTTP_HOST} ^www\.domain2\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

Which redirects www and non-www domain.com to https://domain.com And redirects www and non-www domain2.com to https://domain.com domain2 being a parked domain.

But you can still access https://domain2.com and https://www.domain2.com I want these redirected to https://domain.com Please advise, thanks

2

2 Answers

1
votes

You can combine some of these rules and modify redirect rule for domain2 -> domain to always redirect to https://domain.com:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,NE,L]

RewriteCond %{HTTP_HOST} ^(?:www\.)?domain2\.com$ [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,NE,L]
0
votes

It should be as simple as this:

RewriteCond %{REQUEST_SCHEME} !https [NC,OR]
RewriteCond %{HTTP_HOST} !^domain.com$
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,NE,L]

Still, keep in mind the last comment from @anubhava about configuring VirtualHost and SSL for domain2.com