RewriteCond 更改显示的主机,但不更改服务器

发布于 2024-09-05 08:55:02 字数 748 浏览 11 评论 0原文

输入标题让我相信,出于安全考虑,这可能是不可能的,但无论如何我都会问。我的服务器上运行着短代码支持,我们称之为 xx.yy

我想要它,这样当用户向 xx.yy 发送请求时,它只会更改显示的主机到同一机器上运行的另一个有效域。

到目前为止我已经做到了(让服务器知道接受来自 xx.yy 的请求):

RewriteCond %{HTTP_HOST}   ^.*xx.yy [NC]
RewriteRule ^/(.*)$ http://127.0.0.1:<PORT_OMITTED>%{REQUEST_URI} [P,QSA,L]

RewriteCond %{HTTP_HOST}   ^.*mysite.com [NC]
RewriteRule ^/(.*)$ http://127.0.0.1:<PORT_OMITTED>%{REQUEST_URI} [P,QSA,L]

它有效,并且它将流量引导到我的应用程序中,但网址显示 http://xx .yy 当我宁愿它说 http://mysite.com

我知道我可以重定向到 http://mysite.com 而不是 127.0.0.1,但我有 4 个并行的 mysite.com 盒子,当我已经在这里时,返回 DNS 可能转到另一个盒子似乎是一种浪费。另外,我不确定 POST 请求是如何工作的。

我能做些什么?

Typing out the title to this leads me to believe this might not be possible due to security concerns, but I will ask anyway. I have shortcode support running on my server, lets call it xx.yy

I want it so when a user sends a request to xx.yy, it just changes the displayed host to another valid domain running on the same box.

I have this so far (lets the server know to accept requests from xx.yy):

RewriteCond %{HTTP_HOST}   ^.*xx.yy [NC]
RewriteRule ^/(.*)$ http://127.0.0.1:<PORT_OMITTED>%{REQUEST_URI} [P,QSA,L]

RewriteCond %{HTTP_HOST}   ^.*mysite.com [NC]
RewriteRule ^/(.*)$ http://127.0.0.1:<PORT_OMITTED>%{REQUEST_URI} [P,QSA,L]

It works, and it directs the traffic into my app, but the url says http://xx.yy when I would rather it say http://mysite.com

I know i could redirect to http://mysite.com instead of 127.0.0.1, but I have 4 parallel boxes of mysite.com and going back out to DNS to maybe go to another box seems like a waste when I am already here. Also, I am not sure how POST requests would work like that.

What can I do?

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

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

发布评论

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

评论(1

残龙傲雪 2024-09-12 08:55:02

如果 mysite.com 位于同一个盒子上,并且 DNS 指向那里,只需将 R=301 放入 [P,QSA,L]

示例

RewriteEngine on
RewriteCond %{HTTP_HOST} ^OldDomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.OldDomain.com$
RewriteRule ^(.*)$ http://www.NewDomain.com/$1 [R=301,L]

来自 http://www.liewcf.com/redirect-webpages -to-another-domain-538/

除此之外,尽管没有充分的理由去做你所要求的事情。想象一下,如果有人可以链接到 legalwebsite.com,但将其发送到 evilempire.com。

那就太混乱了,就是这样。

If mysite.com is on the same box, and DNS is pointing there, just put R=301 in [P,QSA,L]

Example

RewriteEngine on
RewriteCond %{HTTP_HOST} ^OldDomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.OldDomain.com$
RewriteRule ^(.*)$ http://www.NewDomain.com/$1 [R=301,L]

From http://www.liewcf.com/redirect-webpages-to-another-domain-538/

Other than that, though there's no way for good reasons to do what you are asking. Imagine if someone could link to legitwebsite.com, but have it get sent to evilempire.com.

It'd be chaos, that's what.

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