apache - 使用 .htaccess 将 example.(us|es) 重定向到子域 (us|es).example.com

标签 apache .htaccess mod-rewrite redirect

我最近为我的网站购买了一个新域,我想将使用旧域访问的任何人重定向到新域。

例如,如果他们去了其中任何一个:

http://www.example.com -- NOT REDIRECT 
http://example.com -- NOT REDIRECT 


http://www.example.us --> http://us.example.com -- REDIRECT
http://www.example.es --> http://es.example.com -- REDIRECT
http://example.us --> http://us.example.com -- REDIRECT
http://example.es --> http://es.example.com -- REDIRECT

您如何使用 .htaccess 文件执行这个简单的 .us|.es -> 子域重定向?任何规则都应适用于所有 URL。

提前致谢。

最佳答案

试试这个:

RewriteCond %{HTTP_HOST} example.us$ 
RewriteRule (.*) http://us.example.com [L,R=301]

RewriteCond %{HTTP_HOST} example.es$ 
RewriteRule (.*) http://es.example.com [L,R=301]

关于apache - 使用 .htaccess 将 example.(us|es) 重定向到子域 (us|es).example.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30140113/

相关文章:

apache - .htaccess http 到 https 和 mvc 查询字符串

java - 多进程监听端口时,tomcat为什么会收到请求?

php - htaccess 将 wordpress 重定向到 index2.php

.htaccess - 使用 .htaccess 密码保护目录及其所有子文件夹

php - 在 Godaddy 上找不到 CodeIgniter 404 页面

PHP:无法加载动态库 intl.so (OSX)

php - 如何编辑/etc/phps/apache2/php.ini

java - 创建.htaccess

regex - nginx子域重写

.htaccess - 使用 htaccess 重定向到照片