Mod_rewrite:将所有内容定向到一个 PHP 文件

发布于 2024-08-24 06:00:32 字数 427 浏览 1 评论 0原文

我有这样的规则:

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !index.php

 RewriteRule ^(.*)$ index.php?req=$1
</IfModule>

如果我请求像 myhost/view/blah 这样不存在的目录,那么一切都会正常工作,但是当我在 URL 中输入一些现有目录时,例如 myhost/module我被重定向到 module/?req=module 而不是停留在 module/

我做错了什么? 我需要将所有内容重定向到index.php(当然除了index.php)。

I have this rule:

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{REQUEST_FILENAME} !index.php

 RewriteRule ^(.*)$ index.php?req=$1
</IfModule>

Everything works fine if I request non-existing directories like myhost/view/blah, but when i enter some existing directory in the url like myhost/module I get redirected to module/?req=module instead of staying at module/

What am I doing wrong?
I would need something that redirects everything to index.php (except index.php, of course).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有心的人 2024-08-31 06:00:32

DirectorySlash 可能会导致此行为。尝试禁用它。

DirectorySlash could cause this behavior. Try to disable it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文