Reputation: 1965
I own multiple domain names under a single main domain as an addon domain.
I also purchased an SSL certificate for the main domain.
To force all non-SSL to SSL, I use the following .htaccess code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^$ https://www.maindomain.com/$1 [R,L]
This works fine, but the issue is if I enter addondomain.info
, it also redirects to https://www.maindomain.com/addondomain.info/
.
I want only the main domain to do https redirection.
How to do that?
Note : If I enter www.addondomain.info
, instead of simply addondomain.info
, it works fine.
Upvotes: 1
Views: 2190
Reputation: 21
May vary depending on your hosting conditions, however in my experience, The Only logic that managed to force all to https and exclude a subdomain in a shared hosting environment looks like:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?ADDON_DOMAIN\.com$ [NC]
RewriteRule .* - [L]
# This is essential in order to ensure no further conditions are applied after navigating to the add-on domain #
RewriteCond %{HTTPS} off
# Now that you've defined your exclusion AND made certain its logic is independent from all other URI Requests, Must re-establish this condition once more #
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 2
Reputation: 143906
Add another condition to it:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$ [NC]
RewriteRule ^$ https://www.maindomain.com/$1 [R,L]
Also, you'll want to place this at the very top of your htaccess file so that it gets applied before any other rules.
Upvotes: 3