1

I have a multiple addon domains on my hosting account. I would like to redirect non-https to https for the main domain AND ONLY ONE of the addon domains.

The problem I am experiencing is www.firstaddondomain.com is not redirecting to https://www.firstaddondomain.com. Instead it does not appear to be redirecting at all. It stays at www.firstaddondomain.com.

Note: I do not want to redirect all http to https. I have another addon domain that I do not want redirected to https.

Here is what my .htaccess file looks like:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$ [NC]
RewriteRule ^$ https://www.maindomain.com/$1 [R,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?firstaddondomain\.com$ [NC]
RewriteRule ^$ https://www.firstaddondomain.com/$1 [R,L]

UPDATE: Thanks for your answer, anubhava. My first addon domain is actually a .org domain, so my updated .htaccess file is slightly different from your answer.

Here is my updated .htaccess file

RewriteEngine On

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

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?maindomain\.com$ [NC]
RewriteRule ^ https://www.maindomain.com%{REQUEST_URI} [R=302,L,NE]
John S
  • 386
  • 1
  • 3
  • 17

2 Answers2

4
  • Your regex isn't capturing $1
  • Both rules can be combined into one

You can use:

RewriteEngine On

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

Make sure this rule is your very first rule and placed in DocumentRoot/.htaccess of both domains.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for your answer. That helped some, but I am still having trouble. I updated my post above. – John S Dec 19 '14 at 16:27
  • I don't think I can...I am using godaddy.com shared hosting. I don't believe I have access to the virtualhost entry. – John S Dec 19 '14 at 18:20
  • I came back and tried the website again today and, correctly, the add on domain that I do not want to redirect to https is not redirecting. I don't know why it didn't work right away. Maybe it was cached? Anyways, thanks for your help! – John S Dec 31 '14 at 02:00
  • Yes it can be a caching problem. Glad it worked out. – anubhava Dec 31 '14 at 03:37
  • 1
    A comment for others - I was trying to do this for an addon domain. I put it in the www directory and bad things happened (redirected to https://addondomain/addondomain). The key that I realized when reading this answer was to put the rewrite rules into the AddonDomain Document Root htaccess file. That works much better. I did have to clear my browser cache as I was making changes. – ds00424 Jun 20 '16 at 21:01
0

May vary depending on your hosting conditions, however in Godaddy shared hosting environments & withOUT a Wildcard SSL, ie- a single domain SSL cert., This is the only config that managed to exclude an add-on domain from a force HTTPS redirect:

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]