0

一个网站位于http://www.siteone.com ,我想将 URL 重写为http://www.anothersite.com/siteone或子域http://siteone.anothersite.com .

该网站将仅托管在http://www.siteone.com,并且不会将任何文件移动或复制到 anothersite.com。

是否可以使用 .htaccess 来做到这一点,还是有其他方法可以做到这一点?

编辑(以下是我在本地主机的 htaccess 中所做的,它似乎不起作用)。不知道我做错了什么。我不想在这个阶段搞乱现场直播。

RewriteCond %{HTTP_HOST} /localhost/mysite [NC] 
RewriteRule ^(.*)$ http://www.anothersite.com/siteone/$1 [L,P] 
ProxyPassReverse /localhost/mysite http://www.anothersite.com/siteone/
4

1 回答 1

0

只要您加载了mod_proxyP ,您就可以使用重写规则中的标志来反向代理请求。您可以在 htaccess 文件中执行此操作:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?siteone.com$ [NC]
RewriteRule ^(.*)$ http://www.anothersite.com/siteone/$1 [L,P]

这将使得当您访问时http://siteone.com/some/path/,请求将被反向代理,http://www.anothersite.com/siteone/some/path/并且该请求的内容将被发送到原始请求。这个在浏览器中的 URL 仍然存在http://siteone.com/some/path/

为了处理重定向之类的事情,您需要设置一个ProxyPassReverse以便位置标头得到属性重写:

ProxyPassReverse / http://www.anothersite.com/siteone/

另请参阅,ProxyPassReverseCookieDomain如果ProxyPassReverseCookiePath该站点www.anothersite.com想要设置 cookie。

注意:虽然该ProxyPass指令只能在 vhost 和服务器配置中使用,但这些ProxyPassReverse指令实际上可以与 mod_rewrite 一起在 htaccess 文件中使用。

于 2012-12-20T21:26:58.687 回答