views:

32

answers:

3

Is it possible to rewrite an url and also block the file extension?.

eg: if I have

`http://www.example.com/search.php?...`

can I rewrite it to

`http://www.example.com/search?` ?

but, blocking the access to the .php file, normally I can access with both ways, with and without the file extension, but I want it to show an error page or 404 if I access with search.php.

Is it possible?.

Thanks.

A: 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} .*\.php
RewriteRule ^(.*)$ error404.html [R=404]
Ignacio Vazquez-Abrams
I can access with .php but not without it.
CSSJediEsck21
That's not what the rules say. Are you sure you applied them properly?
Ignacio Vazquez-Abrams
Ok, now it works, but no quite good, it blocks the file completely. with and without the extension.
CSSJediEsck21
A: 

what is the same with asp.net ??

tesa
A: 

Please consider using the following config:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteRule ^(.*)\.php$ error404.html [R=301,L]
TonyCool