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 overide all subdomain folder

Discussion in 'Workarounds and Optimization' started by hrace009, Nov 6, 2016.

Tags:
  1. hrace009

    hrace009 Well-Known Member

    Joined:
    Dec 24, 2013
    Messages:
    71
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Root
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    I have main domain (DOMAIN.LTD) root directory at /home/user/public_html/
    and sub domain (SUB.DOMAIN.LTD) root directory at /home/user/public_html/sub.domain.ltd/

    and from WHM, i force it to use public_html as document root.

    at the main domain, i have .htaccess like bellow:
    Code:
    Options -Indexes
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
       # First rewrite to HTTPS:
       # Dont put www. here. If it is already there it will be included, if not
       # the subsequent rule will catch it.
       RewriteCond %{HTTPS} off
       RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
       # Now, rewrite any request to the wrong domain to use www.
       RewriteCond %{HTTP_HOST} !^www\.
       RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    </IfModule>
    this htaccess will force to use https://www.domain.ltd

    The problem is, that htaccess will override root directory from SUB.DOMAIN.LTD
    and it will force the SUB.DOMAIN.LTD to be https://www.sub.domain.ltd
    and will make auto SSL fail to obtain certificate for https://sub.domain.ltd
    is there a way to fix this problem without unforce to use public_html ?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    36,995
    Likes Received:
    1,275
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    hrace009 likes this.
  3. hrace009

    hrace009 Well-Known Member

    Joined:
    Dec 24, 2013
    Messages:
    71
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Root
    cPanel Access Level:
    Root Administrator
    Twitter:
    Thank you, i will try for that
     
  4. hrace009

    hrace009 Well-Known Member

    Joined:
    Dec 24, 2013
    Messages:
    71
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Root
    cPanel Access Level:
    Root Administrator
    Twitter:
    can you give me sample costum Mod_Rewrite rules from my case?

    Thank You
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    36,995
    Likes Received:
    1,275
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I've moved this thread to our Workarounds and Optimization forum to allow for user-feedback on custom Mod_Rewrite rules. You may also want to post to a forum such as StackOverflow for specific advice on custom rewrite rules.

    Thanks!
     
  6. hrace009

    hrace009 Well-Known Member

    Joined:
    Dec 24, 2013
    Messages:
    71
    Likes Received:
    10
    Trophy Points:
    8
    Location:
    Root
    cPanel Access Level:
    Root Administrator
    Twitter:
    or if not posible hope cpanel can give ability to edit main directory root path, since i think it will good if all web data in public_html with it's own webroot path
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    36,995
    Likes Received:
    1,275
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Instructions on changing the document root for primary domain name associated with an account are found at:

    Changing DocumentRoot of all sites

    Thank you.
     
Loading...

Share This Page