0

In my htaccess i have this rule.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php

My php extension now is off from my urls.

But the thing is..

If a user types down .php in the end it will load the page.

Is there a way that i can block .php from url?

James Allan
  • 280
  • 5
  • 18
  • 1
    Possible duplicate of [Rewrite file extension BUT deny direct access to file](http://stackoverflow.com/questions/7623725/rewrite-file-extension-but-deny-direct-access-to-file) – cteski Jan 27 '17 at 18:36
  • 1
    You whant that if somebody types in "example.com/index.php" he opens "example.com/index" ? – mirzak Jan 27 '17 at 18:36
  • want to give an error for it, if client types .php – James Allan Jan 27 '17 at 18:37

3 Answers3

4

You can use an additional rule with THE_REQUEST variable to send forbidden error if client sends direct request for .php files:

RewriteEngine On

RewriteCond %{THE_REQUEST} \.php[/\s?] [NC]
RewriteRule ^ - [F]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
2

Add this

RewriteRule ^.*?\.php$ forbidden [F,L]
mirzak
  • 1,043
  • 4
  • 15
  • 30
0
<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^.*?\.php$ forbidden [F,L]

</IfModule>