我有一个名为subdoman,让我们说:
I have a subdoman called, let's say:
cloud.mygizmo.com
不过,当有人浏览到这个网址我希望他们能够真正去:
But when someone navigates to this URL I want them to actually go to:
11.22.33.44/cloud
这是一个完全不同的主机上的 mygizmo.com
,不能移动。
在我的的.htaccess
我有这样的:
RewriteEngine on
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteCond %{HTTP_HOST} ^cloud.mygizmo.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.cloud.mygizmo.com$
RewriteRule ^/?$ "http://11.22.3344/cloud" [L]
这确实做了重定向,但它仍然改变用户的浏览器的地址栏中。
Which does do the redirect, but it still changes the address bar in the user's browser.
我如何使它所以,如果一个用户导航到 cloud.mygizmo.com
他们真正去 11.22.33.44/cloud
,但地址栏还称 cloud.mygizmo.com
?
How do I make it so that if a user navigates to cloud.mygizmo.com
they actually go to 11.22.33.44/cloud
but the address bar still says cloud.mygizmo.com
?
如果您已经mod_proxy的安装,您可以使用 P
标志反向代理代表浏览器
If you have mod_proxy installed, you can use the P
flag to reverse proxy on behalf of the browser:
RewriteEngine on
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteCond %{HTTP_HOST} ^cloud.mygizmo.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.cloud.mygizmo.com$
RewriteRule ^/?$ "http://11.22.3344/cloud" [L,P]
您也可以使用的ProxyPass
或 ProxyPassMatch
反向代理,但这些仅适用于虚拟主机/服务器配置。
You can also reverse proxy using ProxyPass
or ProxyPassMatch
but those will only work in the vhost/server config.
在 cloud.mygizmo.com
/ www.cloud.mygizmo.com
虚拟主机,你可以说:
In the cloud.mygizmo.com
/www.cloud.mygizmo.com
vhost you can say:
ProxyPass / http://11.22.33.44/cloud
然后再提出任何要求的 cloud.mygizmo.com
被代理到 http://11.22.33.44/cloud
主机。
注意的ProxyPass
就像重定向
,它的路径节点连接在一起 /
和 /云
。所以,如果有人去:
Note that ProxyPass
works like Redirect
, it links together the path nodes /
and /cloud
. So if someone were to go to:
http://cloud.mygizmo.com/foo/bar
他们会获取反向代理到:
They'd get reverse proxied to:
http://11.22.33.44/cloud/foo/bar
如果这不是你想要的,然后用 ProxyPassMatch
:
If that's not what you want, then use ProxyPassMatch
:
ProxyPassMatch ^/$ http://11.22.33.44/cloud
另外,如果你想重写规则的行为以同样的方式,你需要捕获请求的URI,并将其与反向引用传递到目标:
Alternatively, if you want the rewrite rule to behave in the same way, you need to capture the request URI and pass it to the target with a backreference:
RewriteRule ^/?(.*)$ http://11.22.33.44/cloud/$1 [L,P]