我已将我的网站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]
答案 0 :(得分: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]