mod_rewrite error 404 if .php

允我心安 提交于 2019-12-12 07:55:39

问题


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 [L]



回答3:


A 301 redirect may be more appropriate for this task.



来源:https://stackoverflow.com/questions/1055652/mod-rewrite-error-404-if-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!