mercredi 29 avril 2015

remove and disallow extensions with .htaccess

I found this script or removing extensions from php files:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

While this works, it still allows files to be accessed if you type them in with their extension, which I don't want.

I tried the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([.]+)$ $1.php [NC,L]

I also tried ^(.*)$ and ^(.+)$

which seems like it should do the job, because it would do this:

index.php -> index.php.php

but somehow, it doesn't work as expected.

So how do I update the above .htaccess script to disallow file extensions?

Aucun commentaire:

Enregistrer un commentaire