0

As you know apache2 is supposed to apply the .htaccess to subfolders if the parent folder has a .htaccess file. My problem is that this does not happen.

I have the folders:

/var/www/program
/var/www/program/rec
/var/www/program/rec2

where I want rec and rec2 to inherit the .htaccess of program. This does not happen.

The .htaccess of program is:

RewriteOptions inherit
RewriteEngine On
RewriteRule ^$ example.php

where https://www.example.com/program redirects to https://www.example.com/program/example.php as desired.

For some reason this does not happen for the two subfolders. No rewrite rule is applied.

If I however put the .htaccess in the subfolder rec, then that works as expected, but rec2 still does not redirect.

I have no other .htaccess in any other parent folder. My /etc/apache2/sites-enabled/000-default contains the following:

<VirtualHost *:443>
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM

    SSLCertificateFile /etc/apache2/ssl/ssl.crt
    SSLCertificateKeyFile /etc/apache2/ssl/private.key
    SSLCertificateChainFile /etc/apache2/ssl/server.ca.pem
    ServerAdmin webmaster@localhost
    Redirect /deluge https://www.example.com:8000
    Redirect /d https://www.example.com:8000
    RewriteOptions inherit

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        RewriteOptions inherit
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
    Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I have tried to find a solution to this problem for a day now.

Kobbe
  • 809
  • 5
  • 16

1 Answers1

0

The problem is that the RewriteRule assumes root is the location of .htaccess, not the current folder.

The following code solves my question.

RewriteOptions inherit
RewriteEngine On
RewriteRule /?$ example.php

This post helped me:

.htaccess RewriteRule not working in subdirectory

Community
  • 1
  • 1
Kobbe
  • 809
  • 5
  • 16