How do I set an .htaccess not to apply to subdirectories?

I am on a shared hosting plan with multiple accounts, which basically means I have one main website and another 10 sites under subdirectories of the main site.
The problem is that the .htaccess from the main site is being applied on all of my subdirectories, causing many problems
Is there a way to prevent an htaccess from being applied to the subdirectories or do I have to override every single command in every single subdir?

Ken,

You DON’T. By definition, .htaccess applies to the resident directory AND ALL SUBDIRECTORIES.

You will NOT be able to “override” a “parent .htaccess” with its “children.” The higher level .htaccess is ALWAYS processed before the child.

You WON’T have this problem IF the subdirectories are also subDOMAINs and are specified with Document_Root as the subdirectory (which puts the main domain’s .htaccess outside the subdomain’s webspace).

Regards,

DK

If you create a .htaccess with “RewriteEngine Off” in the subdirectory, it should stop that.

Err, he didn’t say he’s using mod_rewrite. There are many other mods.

Oh, that’s true. :slight_smile:

Thanks DK!
How do I do this practically? Do I have to set the subdomains via cPanel? or is it some command I have to enter in .htaccess?

Ken,

If it’s not your server then yes you’ll have to use whatever the host provides. CPanel is rather nice this way.

Regards,

DK

Sorry if I bother you but I can’t find how to set the document root with cpanel’s subdomain tools, they just let you “redirect” a subdomain to a directory, which I did, and it doesn’t solve my htaccess problems at all! I googled around for the documentroot directive to use in .htaccess but it gives me a 500 server error :mad: What should I do?

Ken,

Edit:

SORRY! I don’t know how the “train” jumped the track! :blush:

CPanel IS rewriting the httpd.conf for you to direct the subdomains’ Document_Root to the subdirectory. Similar to pippo’s post (changing the domain’s extension - if you own the other domain names), this only requires ownership of the one domain AND the ability to create subdomains. CPanel allow/facilitates this.

The problem is that you will have to link to your subdomains rather than to subdirectories to exclude the main domain’s .htaccess.

Regards,

DK

Hi guys,
I cannot test this, but what about this ?

/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule .* - [L]
your .htaccess directives for example.com here

/sub-dir-of-example-dot-org/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.org$ [NC]
RewriteRule .* - [L]
your .htaccess directives for example.org here

/sub-dir-of-example-dot-net/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example\.net$ [NC]
RewriteRule .* - [L]
your .htaccess directives for example.net here

:slight_smile:

p.s.
When I use RewriteRule .* - [L] does Apache stop parsing the .htaccess at all ?

how does this relate to my problem with documentroot?
:confused:

Ken,

Sorry - see edited post above.

Regards,

DK

Thanks guys! Linking to my subdomains doesn’t seem a very viable option though, so an idea came to my mind: wouldn’t it be easier to host my main domain in a subdirectory itself?
i.e. My domains are currently set up like
Main domain: home/kendothpro/public_html/
Addon domains: home/kendothpro/public_html/addon-com/

I could set them up to be like:
Main domain: home/kendothpro/public_html/maindomain-org/
Addon domains: home/kendothpro/public_html/addon-com/

The main htaccess would then be in a subdirectory and would not affect my addon domains, right? Is it even possible to do this? I tried adding my main domain as an addon but i’m not allowed to, so what if I tried this:

RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com$ [NC]
RewriteRule ^(.*)$ /maindomaindirectory/$1

Ken,

In that case, you wouldn’t need other domains, just redirect the Document_Root to a “main” subdirectory as you suggested - EACH with its own .htaccess.

Nice job - don’t think out of the box, move it to where you need it to be!

Regards,

DK