Allowing Access to Only a Specific Path in .htaccess

I have the following in my .htaccess file:

<Files *.php>
    Order Allow,Deny
    Deny from all
</Files>

<Files index.php>
    Order Allow,Deny
    Allow from all
</Files>

The above code is to restrict access to only the index.php file. However, the problem is that if there is another index.php file under a subdirectory, then that index.php file is allowed to get executed as well. This is not what I want. I want something like:

<Files /home/user/public_html/index.php>
    Order Allow,Deny
    Allow from all
</Files>

and

<Files /home/user/public_html/admin/index.php>
    Order Allow,Deny
    Allow from all
</Files>

(I just want 2 index.php files to be executed)

But the above doesn’t work, as it’ll deny the execution of the should-be-allowed index.php (again, there are two that should be allowed, one under the root directory of the website, and another under the admin folder).

Does anyone have any tips on how to do this?


Source: .htaccess

Leave a Reply