/ / htaccess odmieta prístup k index.php ako index adresára - php, apache, .htaccess

htaccess odmieta prístup k index.php ako indexový adresár - php, apache, .htaccess

Môj súbor .htaccess:

DirectoryIndex index.php

order allow,deny
<FilesMatch "^(index|testfile).php$">
Allow From All
</FilesMatch>

Popiera prístup k koreňovým adresám stránok, ktoré by typicky otvorili index.php. Jediný spôsob načítania stránky je prejsť na stránku mysite.com/index.php namiesto mysite.com Ak ju odstránim order funguje podľa očakávania, ale teraz sú prístupné všetky súbory v tomto adresári.

Ako nakonfigurujem htaccess na zakázanie všetkých súborov okrem index.php ale tiež umožňujú navigáciu mysite.com namiesto mysite.com/index.php?

odpovede:

1 pre odpoveď č. 1

Môžete to urobiť takto:

DirectoryIndex index.php
order Deny,Allow

# deny everything except landing page
<FilesMatch ".">
Deny From All
</FilesMatch>

# allow index.php and testfile.php
<FilesMatch "^(index|testfile).php$">
Allow From All
</FilesMatch>

Alternatívne riešenie použitím mod_rewrite:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !.(?:css|js|png|jpe?g|gif|ico|tiff)$ [NC]
RewriteRule ^(?!(index|testfile).php). - [F,NC]