Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

htaccess - exlude another Domain

Discussion in 'General Discussion' started by clockwork80, Jul 26, 2017.

Tags:
  1. clockwork80

    clockwork80 Registered

    Joined:
    Jul 26, 2017
    Messages:
    4
    Likes Received:
    1
    Trophy Points:
    1
    Location:
    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 %{HTTPSoff
    RewriteCond 
    %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
    RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ ComodoDCV)?$
    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(?:\ ComodoDCV)?$
    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
    RewriteRule ^(.*)$ index.php?$[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!
     
    #1 clockwork80, Jul 26, 2017
    Last edited by a moderator: Jul 26, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,427
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
  3. clockwork80

    clockwork80 Registered

    Joined:
    Jul 26, 2017
    Messages:
    4
    Likes Received:
    1
    Trophy Points:
    1
    Location:
    swiss
    cPanel Access Level:
    Website Owner
    thank u, solved.
     
    cPanelMichael likes this.
Loading...

Share This Page