flip66
flip66

Reputation: 341

Block direct access to php files with rewrite

I'm building a very simple API, but I want to block direct access to php files.

My current .htaccess looks like this:

RewriteEngine on 
Options +FollowSymlinks
RewriteBase / 


RewriteRule ^api/(.*) $1.php/ [L]

So if i go to www.website.com/api/register it should call the register.php file. This works fine, but I want to block somebody from giong to www.website.com/register.php.

Upvotes: 1

Views: 1127

Answers (1)

Peter van der Wal
Peter van der Wal

Reputation: 11856

Add an

RewriteRule (.*)\.php /$1 [L,R=301]

before your current rule

Upvotes: 2

Related Questions