I have next .htaccess in root directory
RewriteEngine on
RewriteRule ^$ index.php [L]
Order Deny,Allow
Deny from all
<Files index.php>
Allow from all
</Files>
And get Page 403 Forbidden for www.example.com instead of www.example.com/index.php.
URL www.example.com/index.php is available.
Access to all files in the root directory is closed. These files are generated by scripts, the file names are unknown.
How to fix it?
Try the following instead:
UPDATE: Added missed anchors!
(Although I would assume you are on Apache 2.4, so you should be using the corresponding
Requiredirectives instead ofOrder,DenyandAllow.)Alternatively, replace all you existing directives with the following:
This allows access to both
example.com/andexample.com/index.php. To block direct access toindex.phpthen try the following instead:mod_dir (ie. "DirectoryIndex") is processed after mod_rewrite.
This rule is redundant, it should be handled by
DirectoryIndexinstead.UPDATE:
By adding another rule it would end up blocking both URLs. Since one or other rule will always be successful.
You can use regex alternation in a single rule. For example:
The same regex could be used in the
<FilesMatch>container above.Or, if you have many such exceptions, it might be more readable to have multiple conditions. For example:
Note, however, like your original rule, this also blocks URLs in "subdirectories", not just the root directory.