views:

793

answers:

3

I rewrite my urls to be user friendly. For example I have a page called user.php that I rewrite to /user. But a user can still use user.php. Can I redirect to a 404 if they request a page with a .php extension?

Options -MultiViews +FollowSymlinks -Indexes
RewriteEngine on


RewriteRule ^user/([0-9]+)$ user.php?id=$1 [L,QSA]

Thanks.

+3  A: 
RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/
RewriteRule ^.*$ - [R=404,L]
cletus
Pretty sure R=404 isn't one of the status codes that flag accepts...
Gabriel Hurley
that works but i can still access the page if i add a question mark after user.php?. maybe i can do something about that to?
fair enough. can't argue if it works.
Gabriel Hurley
@Tony: actually you're quite right. Fixed.
cletus
thank you cletus youre awesome
+1  A: 

This should do the trick, I think:

RewriteRule (.*)\.php$ path/to/your/404file [L]
Gabriel Hurley
so i need to add rule for all my pages?
A: 

A 301 redirect may be more appropriate for this task.

Alex Barrett