.htaccess - 如何使用 htaccess 将子域(包含所有文件夹和文件)重定向到另一个域?
问题描述
我想将 subdomain.example.com 和子域访问的所有可能的 URL(如 subdomain.example.com/somefolder/somefile.php)重定向到另一个域 example-two.com。htaccess可以吗?
解决方案
对于将 subdomain.example.com/any-address 重定向到 example-two.com 将此规则添加到您的 subdomain.example.com .htaccess 文件的顶部
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
RewriteRule (.*) http://example-two.com/ [R=301,L]
</IfModule>
对于将 subdomain.example.com/any-address 重定向到 example-two.com/any-address 将此规则添加到您的 subdomain.example.com .htaccess 文件的顶部
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com [NC]
RewriteRule (.*) http://example-two.com/$1 [R=301,L]
</IfModule>
推荐阅读
- react-native-android - Expo SDK 需要 Expo 才能运行。看来是本地人
- python - 是否需要将数据分成三份;训练、验证和测试?
- artifactory - 使用 JFrog 访问 SAP NPM 存储库失败
- java - java.lang.NumberFormatException:Android 中的空字符串
- agent - 如何在 AnyLogic 中定义一组代理中的特定代理?
- html - AJAX 移动到 Django 项目中的另一个 js 文件时失败
- java - 如何检查数组是否包含重复项,如果不包含则仅返回
- ios - UIStackview 保持子视图右对齐,即使其他视图被隐藏
- java - 是否可以在不使用 Spring 框架的情况下在每个 JUnit 测试用例之后回滚数据库?
- java - 如何使用父类引用访问子类方法?