clockwork80

Registered
Jul 26, 2017
4
1
1
swiss
cPanel Access Level
Website Owner
Hello!

Let me explain my problem.Nobody can answer this,and now im here :)

1x Main-Domain (SSL) public_html/FILES
1x Addon-Domain (SSL) public_html/DOMAIN.COM <(Files inside)

The Main-Domain have one .htaccess to force ssl - this works here are no problems.
But all non SSL visitors on the Addon-Domain get a redirect to the Main-Domain

Some hours later i found some ways to exlude the Addon-Domain from the .htaccess rules.

But witch is the best way ?




1. Force SSl for the second Domain

PHP:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

2.Exclude the second Domain on the "main" htaccess


PHP:
### RewriteEngine On ###
<IfModule mod_rewrite.c>
RewriteEngine On
### http -> https ###
RewriteCond %{HTTP_HOST} ^(www\.)?SECOND-DOMAIN\.com$
RewriteRule ^.*$ '-' [L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule (.*) https://MAIN-DOMAIN.COM%{REQUEST_URI} [R=301,L]
### Rewrite application ###
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
### Close RewriteEngine ###
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>

3. I use a shared host, what can my provider do,to "split" this two Domains?


Thanks!
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,222
463
Hello,

One option to consider is to check with your hosting provider to see if they can disable the following option under the "Domains" tab in "WHM >> Tweak Settings":

Restrict document roots to public_html

This would allow you to move your addon domain name outside of the public_html directory so it's not affected by the .htaccess rules in the public_html directory. Otherwise, you'd need to exclude the addon domain name from the rewrite rules configured in the .htaccess file located in the public_html directory. Here's a third-party URL where rules like that are discussed:

.htaccess mod_rewrite - how to exclude addon domain from rewrite rule?

Thank you.