I want to prevent direct .php file access. This below 2 lines works fine
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php - [F,L]
But, it won't open index.php file. I want to prevent direct .php file access except index.php file
I want to prevent direct .php file access. This below 2 lines works fine
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php - [F,L]
But, it won't open index.php file. I want to prevent direct .php file access except index.php file
Add a condition to not apply the rule to the specific file:
RewriteCond $1 !^(index\.php)$
To prevent direct access to all .php files except index.php you can use this rule:
RewriteCond %{THE_REQUEST} \.php[?/] [NC]
RewriteRule !^index\.php$ - [F,L,NC]
You need to use %{THE_REQUEST} variable for this. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^index\.php$ - [F,L]
Options +FollowSymlinks
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !^(.+).css$ 
RewriteCond %{REQUEST_FILENAME} !^(.+).js$ 
RewriteCond %{REQUEST_FILENAME} !index.php$ 
RewriteRule ^(.+)$ /deny/ [nc] 
Access to files "CSS" and "JS" and "index.php" will be there. Other requests will be redirect to "Deny" folders.