mod_rewrite 错误 404 如果 .php

2021-12-21 00:00:00 php mod-rewrite

我重写了我的网址以方便用户使用.例如,我有一个名为 user.php 的页面,我将其重写为/user.但是用户仍然可以使用 user.php.如果他们请求带有 .php 扩展名的页面,我可以重定向到 404 吗?

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]

谢谢.

推荐答案

RewriteCond %{THE_REQUEST} .php[ /?].*HTTP/
RewriteRule ^.*$ - [R=404,L]

相关文章