.htaccess 重写子域
这是我当前的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有看到重写域的规则;也许这是你的问题。使用您的代码,尝试:
我希望这会对您有所帮助
杰罗姆·瓦格纳
I don't see the rule rewriting the domain ; maybe this is your problem. Using your code, try:
I hope this will help you
Jerome WAGNER
我将 P(代理)标志添加到规则中并且它起作用了。
I added the P (proxy) flag to the rule and it worked.