未找到 Htaccess 重写

发布于 2024-08-21 15:20:13 字数 248 浏览 2 评论 0原文

我正在使用Mod Rewrite来删除index.php。我不想使用查询。我希望 foo.com/bar 被解释为 foo.com/index.php/bar

它做得很好,但给我未找到错误。在此服务器上找不到请求的 URL /home/foo/www/index.php/bar。

为什么!!

I'm using Mod Rewrite to remove index.php. I do not want to use queries. I want foo.com/bar to be interpreted as foo.com/index.php/bar.

It does this fine, but gives me Not Found error. The requested URL /home/foo/www/index.php/bar was not found on this server.

Why!!

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

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

发布评论

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

评论(2

苍白女子 2024-08-28 15:20:13

更新

我想我刚刚弄清楚你想要做什么。你看,你可以在幕后传递查询,但你不能在幕后传递你的建议。您必须进行实际的重定向。像这样的东西(重要的部分是R):

RewriteRule ^bar$ index.php/bar [NC,QSA,R]

这会强制使用新的特殊路径重定向到您的页面。这就是你想要的吗?

原始答案

您不能将路径传递到这样的 PHP 页面,因为它将被解释为路径的一部分。您的文件很可能位于 Linux/Unix 计算机上,其中的目录可以使用 . 命名。抱歉,但您必须使用查询字符串:

RewriteBase /
RewriteRule ^bar$ index.php?page=bar [NC,QSA]

更新

RewriteBase /
RewriteRule ^bar$ index.php?/bar [NC,QSA]

我还认为 Windows 的最后几个版本支持目录中的 .好吧,但我不确定。

Update

I think I just figured out what you are wanting to do. You see, you can pass queries behind the scenes, but you cannot pass what you are suggesting behind the scenes. You have to do an actual redirect. Something like this (The important part is the R):

RewriteRule ^bar$ index.php/bar [NC,QSA,R]

This forces a redirect to your page using the new special path. Is that what you wanted?

Original Answer

You cannot pass a path to a PHP page like that as it will be interpreted as part of a path. Chances are, your file is on a Linux/Unix machine where a directory can be named with a . in it. Sorry, but you will have to use a query string:

RewriteBase /
RewriteRule ^bar$ index.php?page=bar [NC,QSA]

Or updated:

RewriteBase /
RewriteRule ^bar$ index.php?/bar [NC,QSA]

I also think the last few versions of windows support . in directories as well, but I am not sure.

巷子口的你 2024-08-28 15:20:13

index.php 几乎可以肯定是一个文件,而不是目录,除非您(奇怪地)有一个名为 index.php 的目录。 Apache 正确地抱怨没有这样的目录。

您可能打算执行类似 index.php?page=bar 的操作。相应地调整您的 .htaccess

index.php is almost certainly a file, not a directory, unless you (bizarrely) have a directory called index.php. Apache is correctly complaining that there is no such directory.

You probably meant to do something like index.php?page=bar. Adjust your .htaccess accordingly.

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