mod_rewrite - 奇怪的 [R] 行为

发布于 2024-09-06 02:56:10 字数 435 浏览 3 评论 0原文

我正在用 mod_rewrite 做一些非常简单的事情,但它的行为很奇怪。它的行为就好像我正在使用 [R] 选项,但我没有。下面是对 .htaccess 文件的简单测试:

RewriteEngine on
RewriteRule ^page1$ page2

这应该将对 page1 的请求重定向到 page2,但使 Web 浏览器中的 URL 仍指向 page1。但这并没有发生。它实际上将 URL 切换到 page2,就好像我正在使用这段代码一样:

RewriteRule ^page1$ page2 [R]

为什么要这样做?这不是默认行为。我正在使用为 EC2 预配置的机器,因此它可能是我不知道的 apache 配置中的某些内容。谷歌搜索是徒劳的。帮助?

顺便说一句,这是 Apache 2.12。

I'm doing something very simple with mod_rewrite and it's behaving strange. It's behaving as if I'm using the [R] option, but I'm not. Here's a simple test for a .htaccess file:

RewriteEngine on
RewriteRule ^page1$ page2

This should redirect a request for page1 to page2, but leave the URL in the web browser still pointing to page1. That doesn't happen though. It actually switches the URL to page2, as if I were using this code:

RewriteRule ^page1$ page2 [R]

Why's it doing that? That's not the default behavior. I'm using a pre-configured machine I got for EC2, so it's probably something in the apache configuration I'm not aware of. Googling has been futile. Help?

This is Apache 2.12 btw.

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

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

发布评论

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

评论(2

碍人泪离人颜 2024-09-13 02:56:10

DirectorySlash 通常是罪魁祸首。如果没有,并且不再进行进一步重写,请考虑使用 [L]

DirectorySlash is often the culprit. If not, and no further rewriting is done, consider using [L]

怪我入戏太深 2024-09-13 02:56:10

我修复了它......不太确定我做了什么(doh!),因为我花了很多时间。
我将尝试进行一些调查工作,以便分享解决方案。

谢谢!

I fixed it... not exactly sure what I did (doh!) because I futzed around with it a bunch.
I'll try to to some investigative work so I can share the solution.

Thanks!

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