Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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} 
like image 870
user3470981 Avatar asked Feb 02 '26 07:02

user3470981


2 Answers

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]
like image 117
anubhava Avatar answered Feb 05 '26 09:02

anubhava


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$
like image 33
Miguel Ortiz Avatar answered Feb 05 '26 09:02

Miguel Ortiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!