首页 > 解决方案 > htaccess URL 掩码子文件夹到另一个域而不是重定向

问题描述

我需要将www.domain.com/folder重定向到 subdomain.anotherdomain.com 而不更改第一个网址www.domain.com/folder。在www.domain.com我有一个 WordPress 网站,在 subdomain.anotherdomain.com 中有一个 Moodle 网站。这样,只有www.domain.com/folder必须有重定向,而不是www.domain.comwww.domain.com/other_folder。可以办到?这是可能的?。

在 Worpress 网站上,我有这个:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

我尝试使用 iframe,但 Google Chrome 不喜欢这样:/(cookie 问题)

提前谢谢了。

标签: .htaccessmod-rewrite

解决方案


您不能以某种方式保持指向一个 http 服务器的 URL 在浏览器的 URL 栏中可见,而是让它连接到其他一些 http 服务器。那将是一个巨大的安全问题。

如果您可以更改设置,使两个主机名都指向同一个 http 服务器,那么您所要求的可以通过应用一些简单的内部重写规则来实现。

对于单独的 http 服务器,您唯一的选择是使用 apache http 服务器带来的代理模块,如果它已安装并启用...

ProxyPass /folder https://subdomain.anotherdomain.com
ProxyPassReverse /folder https://subdomain.anotherdomain.com

有关详细信息,请参阅代理模块的文档:http ://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass

代理模块也可以重写模块中使用,但这会带来可选的速度降低:

RewriteEngine on
RewriteRule ^/?folder/(.*)$ https://subdomain.anotherdomain.com/$1 [P,QSA,END]

这再次记录在重写模块中: http ://httpd.apache.org/docs/current/rewrite/flags.html#flag_p


推荐阅读