php - mod_rewrite 错误 404 如果 .php

标签 php mod-rewrite

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

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]

关于php - mod_rewrite 错误 404 如果 .php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1055652/

相关文章:

php - MySQL:如何从表中获取具有指定值的某些列?

php - select records form tableA and tableB where tableA.id = tableB.id, records from tableA 一次

php - Sendbird/Guzzle 返回 "The request body is an invalid JSON"

url - MOD_REWRITE 规则无法忽略变量

PHP 必填字段

php - 为什么订单总计未显示在 Magento 报告和最后 5 个订单网格中?

php - .htaccess错误无法按预期工作

Apache 服务器上的 Angular 应用程序无需重写规则

css - 在 htaccess 中使用 RewriteRule 后,在 html 中使用时不会加载相对路径

.htaccess - 在执行第一个规则后运行第二个重写条件和规则