mod_rewrite error 404 if .php
问题 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. 回答1: RewriteCond %{THE_REQUEST} \.php[\ /?].*HTTP/ RewriteRule ^.*$ - [R=404,L] 回答2: This should do the trick, I think: RewriteRule (.*)\.php$ path/to/your/404file