.htaccess 重写子域

发布于 2024-08-27 22:01:34 字数 664 浏览 3 评论 0原文

这是我当前的代码:

RewriteCond %{HTTP_HOST} !^example\.com [NC] 
#RewriteCond %{REQUEST_URI}!^something
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com 
RewriteRule (.*) something/%1/$1 [QSA,L]

我的目标是将 http://*.example.com/whatever 重写为 http://example.com/something/*/whatever ,假设两者的 * 相同,并且 whatever 两者相同。但是,我相信这会以某种方式导致无限循环,因此我添加了注释掉的行(RewriteBase is / btw),但如果我取消注释,则整个站点都是 500 响应代码。如果没有该行,则只有子域错误。

我做错了什么,我该如何解决这个问题?我已经配置了服务器,因此所有内容都会重定向到我的 public_html 文件夹。

编辑:为了澄清,我正在尝试进行内部重定向,而不是外部重定向。

编辑:似乎没有内部重定向标志。有没有什么地方可以看到损坏的重写规则的实际错误消息?如果我知道出了什么问题,我就有更好的机会解决它。

Here is my current code:

RewriteCond %{HTTP_HOST} !^example\.com [NC] 
#RewriteCond %{REQUEST_URI}!^something
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com 
RewriteRule (.*) something/%1/$1 [QSA,L]

My goal is to rewrite http://*.example.com/whatever to http://example.com/something/*/whatever, assuming * is the same for both and whatever is the same for both. However, I believe this is causing an infinite loop somehow, so I added that commented out line (RewriteBase is / btw), but if I uncomment then the entire site is a 500 response code. Without that line, only the subdomains error.

What am I doing wrong, and how can I fix this? I have already configured the server so anything gets redirected to my public_html folder.

EDIT: For clarification, I am trying to do an internal redirect, not external.

EDIT: There is not a flag for internal redirect it seems. Is there any place I can see the actual error message for the broken rewriterule? If I knew what was wrong I would be able to stand a better chance of fixing it.

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

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

发布评论

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

评论(2

内心荒芜 2024-09-03 22:01:34

我没有看到重写域的规则;也许这是你的问题。使用您的代码,尝试:

RewriteCond %{HTTP_HOST} !^example\.com [NC] 
#RewriteCond %{REQUEST_URI}!^something
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com 
RewriteRule (.*) http://example.com/something/%1/$1 [QSA,L]

我希望这会对您有所帮助
杰罗姆·瓦格纳

I don't see the rule rewriting the domain ; maybe this is your problem. Using your code, try:

RewriteCond %{HTTP_HOST} !^example\.com [NC] 
#RewriteCond %{REQUEST_URI}!^something
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com 
RewriteRule (.*) http://example.com/something/%1/$1 [QSA,L]

I hope this will help you
Jerome WAGNER

篱下浅笙歌 2024-09-03 22:01:34

我将 P(代理)标志添加到规则中并且它起作用了。

I added the P (proxy) flag to the rule and it worked.

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