【发布时间】:2019-02-20 07:15:39
【问题描述】:
我当前的 .htaccess mod_rewrite 配置有问题。
这是我当前的代码:
RewriteRule ^([^/]*)/([^/]*)\/$ /game.php?id=$1&title=$2 [L]
RewriteRule ^([^/]*)\/$ /index.php?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /category.php?cid=$1&page=$2&title=$3 [L]
上面的代码正确地重写了我的 URL。但是,每当我在浏览器中输入一个不存在的目录时,例如http://www.example.com/non-existent-directory/,我的主页就会出现,而不是我设置的 404 页面。
另一个注意事项,尾部的斜线似乎有很大的不同。如果我从 URL 中删除尾部斜杠,即 http://www.example.com/non-existent-directory,则 404 页面会正确显示。如果我添加它,我的主页会出现,而不是应有的 404 页面。
有谁知道我需要做什么才能让我的 URL 重写,但在我键入不存在的目录时也会显示 404 页面?
提前谢谢你。
【问题讨论】:
标签: .htaccess