1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Root .htaccess File Hijacks my Subdomain .Htaccess File

Discussion in 'Apache' started by charles99, Sep 2, 2015.

  1. #2
    I am running into problems with my root .htaccess file is hijacking the .htaccess file in my subdomain. I have tried to exclude my subdomain only to run into a blank screen. I have tried with Rewrite off in my subdomain. But with both needing different rules to function I am looking for a way to get around the root inheritance structure, so the my .htaccess file in my subdomain will work.

    Over the last 14 days I have tried over 6 different to get both .htaccess files to work so I am hoping someone in the forum have a answer so I can get some sleep! People are starting to ask me if I am in the cast of The Walk Dead!:)

    #Exclude subdomain folder
    RewriteEngine On
    RewriteRule ^(sub)($|/) - [L]
    or
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/sub/.*$
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1
    or
    RewriteEngine on
    RewriteRule ^sub($|/) - [L]
    or
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^mainsite\.com
    RewriteCond %{HTTP_HOST} !^sub\.mainsite\.com$
    RewriteRule (.*) http://www.mainsite.com/$1 [R=301,L]
    or
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sub\.mainsite\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.sub\.mainsite\.com$
    RewriteRule ^/?$ "\-" [R=301,L]
    or
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    # If requested URI does not end in "/"
    RewriteCond $1 !/$
    # add a trailing slash
    RewriteRule ^(.+)$ /$1/ [R=301,L]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.mainsite\.com:)80)?$
    RewriteCond %{DOCUMENT_ROOT}/sub/%1/%{REQUEST_URI} -d [OR]
    RewriteCond %{DOCUMENT_ROOT}/sub/%1/%{REQUEST_URI} -f
    RewriteRule (.*) /sub/%1/$1 [L]
    SEMrush
     
    Last edited by a moderator: Sep 2, 2015
    charles99, Sep 2, 2015 IP
    SEMrush
  2. [ET]Alexander

    [ET]Alexander Well-Known Member

    Messages:
    66
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    100
    #3
    There is a simple fix for this,
    create a .htaccess file in the directory you would like to exclude with only:

    RewriteEngine Off

    Unless you want to have rules in the subdirectory, in that case, just fill in the rules and they will null the ones in the root directory.
     
    [ET]Alexander, Sep 2, 2015 IP
  3. charles99

    charles99 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Tried turning RewriteEngine Off, and working with the rewrite rules that came with my software htaccess file but it didn't work. Kept running into a blank screen or file didn't exist error. I know there as to be way to get around the htaccess files when it come to sudomain? I was given this and its the second time. But I couldn't get it to work, plus it requires you to add a prefix "sd" to my sub-domain; please review I am not sure if this would work either


    RewriteEngine On
    Options -MultiViews

    RewriteCond $1!/$
    RewriteCond $1!\.
    RewriteRule ^(.+)$ /$1/ [R=301,L]

    RewriteCond %{REQUEST_URI}!^/sd_
    RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
    RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
    RewriteRule (.*) /sd_%1/$1 [L]
     
    charles99, Sep 2, 2015 IP
  4. [ET]Alexander

    [ET]Alexander Well-Known Member

    Messages:
    66
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    100
    #5
    So you created a second .htaccess file in the directory that is assigned to your subdomain?
    We have faced this issue with numerous customers utilizing the Apache webserver, seemingly we have not had this issue since all of our servers were upgraded to use LiteSpeed. The resoultion every time was to create a second .htaccess in the directory that is assigned to the subdomain and in that file disable rewrite engine.
     
    [ET]Alexander, Sep 3, 2015 IP