Reputation: 13
I am using the following .htaccess file to direct all my users from HTTP to https://www.mysite.com
which works fine (https://www.
are prefixed all the time).
rewriteengine on
rewritecond %{HTTP_HOST} !^www\.
rewriterule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
rewritecond %{HTTPS} !=on
rewriterule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
My Problem is that other secondary domains (which don't have SSL) which are hosted on the same hosting are trying to go to https://www.myanothersite.com
to which the browser shows the security error. Disabling the .htaccess
files removes the security error from my secondary domains but then my primary domain is not redirected to https://
.
How should I rewrite the .htaccess
file so that my primary domain (which has SSL) resolves to https://www.mysite.com
and my secondary domains on the same hosting resolve to www.myanothersite.com
? (www.
should always be prefixed on my secondary domains).
Upvotes: 1
Views: 844
Reputation: 785561
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# add www.
rewritecond %{HTTP_HOST} !^(www|[0-9]+)\. [NC]
rewriterule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# rdirect to https only for primary.com
rewritecond %{HTTPS} !=on
rewritecond %{HTTP_HOST} ^(www\.)?promary\.com$ [NC]
rewriterule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Upvotes: 1