Reputation:
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.
Upvotes: 8
Views: 4454
Reputation: 625317
RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/
RewriteRule ^.*$ - [R=404,L]
Upvotes: 7
Reputation: 40072
This should do the trick, I think:
RewriteRule (.*)\.php$ path/to/your/404file [L]
Upvotes: 2