将动态子域重定向到与子页面相同的子域。如何?
我有点被困在这里了。我需要获得有关此子域情况的帮助。
我需要将 http://dynamicsubdomain.example.com/
重定向到 http://dynamicsubdomain.example.com/account/welcome.html
。 我该怎么做?我尝试了几件事,但都没有结果。主要问题是我无法从 mod_rewrite 的 %{HTTP_POST}
字符串中获取输入的动态子域。
另一个问题是它正在创建无限循环。因此,它仅需要在这些条件下进行重定向,而不是在存在像 http://dynamicsubdomain.example.com/test/page.html
这样的 URL 时进行重定向。因为否则它将创建无限循环。它仅适用于网站的起始页面。
我希望你们都能帮助我,这是我项目中最后但很重要的事情之一。
提前致谢!
I'm a little stuck in here. I need to get some help with this subdomain-situation.
I need to redirect http://dynamicsubdomain.example.com/
tohttp://dynamicsubdomain.example.com/account/welcome.html
.
How do I do this? I tried several things but all without result. The main problem is that I can't fetch the entered dynamic subdomain from the %{HTTP_POST}
string from mod_rewrite.
Another issue would be that it's creating and endless loop. So it only needs to redirect on these conditions, not when there's a URL like http://dynamicsubdomain.example.com/test/page.html
. Because else it will create and endless loop. It's just for the starting page from the website.
I hope y'all can help me out, it's one of the last but important things from my project.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
URL 重定向 wiki 页面上有多个选项。例如,如何在根目录中删除一个重定向到目的地的index.php?
There are several options on the URL redirection wiki page. For example, how about dropping an index.php in the root that redirects to the destination?
如果您停留在同一个域中,并且只是重定向到不同的路径,为什么域如此重要?
Apache 中的 UseCanonical 设置可能对此有影响,但默认为打开,这会保留请求中指定的主机和端口。
Why does the domain matter so much if you are staying on the same domain, and just redirecting to a different path?
The UseCanonical setting in Apache may have an effect on this, but it is defaulted to on, which preserves the host and port specified in the request.
嘿伙计们,感谢您的支持/帮助,但我自己找到了解决方案。比我想象的要快:)
这就是诀窍,我希望我可以帮助某人:
@gahooa:我需要这样做,因为我的主页 example.com 只是一种没有特殊内容的登陆页面。 URL“account/welcome.html”的额外部分用于显示与“子域”帐户相关的页面(例如 gahooa.example.com 将显示您的个人资料页面)。在我的应用程序中,我通过 preg_match 捕获子域,因此它知道必须加载的女巫帐户。我希望我很清楚:)但无论如何还是谢谢!
这是我第一次使用 Stackoverflow,但它实际上效果很好!专家回复很快,辛苦了!我一定会回来的:)
Hey guys, thanks for your support/help but I found the solution myself. Quicker than I thought :)
This is what does the trick, I hope I can help someone with this:
@gahooa: I need to do this because my mainpage example.com is just a sort of landing-page with no special things. The extra part of the URL "account/welcome.html" is for showing a page related to the "subdomains"-account (gahooa.example.com for example will show your profile page). In my app I catch up the subdomain by a preg_match so it knows witch account it has to load. I hope I'm clear :) But thanks anyway!
This is my first time i'm using Stackoverflow but it actually works great! Quick replies from experts, great work! I definitely will come back :)
如果您确实想使用
HTTP_HOST
:但是就像 gahooa 已经说过的那样,如果您使用同一主机,则无需指定绝对 URL。 URL 路径就足够了:
If you really want to use
HTTP_HOST
:But like gahooa already said you don’t specify an absolute URL if you stay with the same host. The URL path will suffice: