.htaccess - 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.com或www.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 问题)
提前谢谢了。
解决方案
您不能以某种方式保持指向一个 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
推荐阅读
- java - 在 assertEquals 中使用方括号的 Java 事件驱动开发问题
- swift - Swift Eureka:更新 Eureka tableView 的样式
- html - Bootstrap 4表单字段未水平对齐
- amazon-web-services - 如何使用 lambda 函数 AWS SAM 添加访问密钥的策略
- python - 从 Amazon Product Advertising API 5.0 中提取“About this item”
- react-native - 没有结果 react-native-searchable-dropdown
- kotlin - How does assigning KeySetView to MultableSet works in Kotlin when they are of different implementation hirarchy
- c# - 如何使用 C# 中的 SQlite 将按钮的颜色从一种形式更改为另一种形式
- c++ - 为什么我的 unique_ptr 会立即自行删除?
- c# - 按 EF Core 中 varchar/nvarchar 列值的长度对结果进行排序