user3470981
user3470981

Reputation: 31

I need to force ssl on main domain but not subdomain

The main site at www.mydomain.com is set up as a secure site using an SSL certificate.

I need to create a subdomain that is not secured (http://open.mydomain.com).

I'm hosting with InMotionHosting.com. I've created the subdomain in cPanel and pointed it to the folder at public_html/open (the main site is at public_html/mainsite) but when I try to visit the subdomain URL I get an SSL error in Chrome, and in IE I get redirected to https://www.mydomain.com/open.

How do I fix this?

Here is my .htaccess file:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

Upvotes: 3

Views: 905

Answers (2)

Miguel Ortiz
Miguel Ortiz

Reputation: 1482

This worked for me:

<IfModule mod_rewrite.c>

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

</IfModule>

If you want several subdomains change the line like this:

RewriteCond %{HTTP_HOST} !^(sub|lolo).example.com$

Upvotes: 2

anubhava
anubhava

Reputation: 785176

Change your rules to this:

RewriteEngine on
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Upvotes: 2

Related Questions