启用 mod_rewrite 和 .htaccess 通过 httpd.conf 然后将此代码放入您的 DOCUMENT_ROOT/.htaccess 文件:
mod_rewrite
.htaccess
httpd.conf
DOCUMENT_ROOT/.htaccess
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # For mobile devices: RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC] RewriteCond %{HTTP_USER_AGENT} (android|blackberry|iphone|ipod|windows phone) [NC] RewriteRule ^ http://test2.com/ [L,R=301] # For non-mobile devices: RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC] RewriteRule ^(.*)$ http://test2.com/$1 [L,R=301]