Wednesday, August 31, 2022

[SOLVED] apache AllowOverride /var/www/html but not /var/www/html/temp/

Issue

I have a wordpress site, Because wordpress need .htaccess rule, so /var/www/html should be set AllowOverride all. But I have some custom folder /var/www/html/temp/, it has many sub-folder, the max depth could be 9. /var/www/html/temp/images/avatar/username/large/cache/image.jpeg. How to add another rule, so that <directory "/var/www/html/temp"> could be with rule AllowOverride None,thanks.

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html
    <directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

Solution

There's not really a trick here, if you create a 2nd directory section that is conceptually below the first, its changes will be merged in:

<Directory "/var/www/html/temp">
  AllowOverride None
</Directory>

For clarity, just put it immediately after the existing Directory section, although for Directory that is not strictly necessary.

You should review the basics of the "configuration sections" topic in the manual.



Answered By - covener
Answer Checked By - Mary Flores (WPSolving Volunteer)