Extend depth of .htaccess to all subfolders and their children

21,318

Solution 1

Are you using Apache? Subdirectories are supposed to inherit .htaccess by default under Apache.

Check your /etc/apache2/httpd.conf file. It could be that you have a <Directory> directive that is keeping your .htaccess from being applied to subdirectories, like it should by default.

Solution 2

I was having this trouble as well.

And it turned out the solution is quite simple:

In your "main" .htaccess under /your_root/, add the following lines:

RewriteBase /your_root/

RewriteOptions InheritDown

Share:
21,318

Related videos on Youtube

JoXll
Author by

JoXll

Updated on September 18, 2022

Comments

  • JoXll
    JoXll almost 2 years

    I need to be able to use .htaccess in all subfolders for full depth. E.g. I have .htaccess in public_html folder:

    \public_html\.htaccess
    

    How I make it to work for the folder small as well?

    \public_html\home\images\red\thumbs\small\
    

    It only enforces up to home directory not more.

    ErrorDocument 403 http://google.com
    Order Deny,Allow
    Deny from all
    Allow from 11.22.33.44
    
    
    
    Options +FollowSymlinks
    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    • Su'
      Su' over 12 years
      htaccess rules do inherit to sub-directories. See here If you're not seeing that behavior, it's more likely a problem with the rules themselves, and you need to provide an example.
    • jflaflamme
      jflaflamme over 12 years
      @Su' Can you post your comment as an answer
  • JKB
    JKB about 3 years
    This is good! Only found the opposite solution so far (setting the inheritance from within the deeper level .htaccess). Works with apache 2.4.8 and later.