1

我已将我的站点 test.com 的域名更改为 test2.com

域名从test.com to test2.com

I want to know if all the pages like test.com/* will be redirected to test2.com/*

在 test2.com 中,我正在 mod_rewrite 中编写重写规则来识别智能移动设备。

For all smart phone I would like to redirect requests test.com/* to test2.com (home page)

For every non smart phone I would like to redirect test.com/* to test2.com/*

为此,我研究了以下条件。我不确定这是否正确。

我试过这样的事情。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [AND]
RewriteCond %{HTTP_USER_AGENT} mobile
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|iphone|ipod|windows phone) [NC]
RewriteRule ^(.*)$ http://test2.com/mobil/#1 [L]
4

1 回答 1

1

启用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]
于 2013-09-25T12:57:51.393 回答