HtAccess Rewrite 适用于 [R],但失败并适用于 [L]

发布于 2025-01-01 20:00:22 字数 547 浏览 1 评论 0原文

所以,我试图将: sub.example.com/page 重写为 www.example.com/sub/page

我有这段代码可以工作(注意最后一个字符):

RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [R]

而这段代码不能:

RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [L]

我想要 url保持用户输入的状态,但这似乎会产生 500 错误。我已启用日志记录来尝试提供帮助,但它没有提供任何线索。这可能吗?

So, I am trying to make: sub.example.com/page rewrite to www.example.com/sub/page

I have this code which does work (note last character):

RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [R]

And this code that does not:

RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).example.com [NC]
RewriteRule ^(.*) http://www.example.com/%1/$1 [L]

I want the url to remain as the user typed it in, but this seems to produce a 500 error. I've enabled logging to try to assist, but it doesn't provide any clues. Is this possible?

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

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

发布评论

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

评论(1

兔姬 2025-01-08 20:00:22

尝试将最后一条规则更改为

RewriteRule ^(.*) http://www.example.com/%1/$1 [P]

如果您列出目录结构以显示 sub.example.comwww.example.com 的关联方式,则也可以通过重写与上面更昂贵(更慢)的代理解决方案。

Try changing the last Rule to

RewriteRule ^(.*) http://www.example.com/%1/$1 [P]

If you list your directory structure to show how sub.example.com and www.example.com are related, this may also be possible via a rewrite vs the more expensive (slower) proxy solution above.

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