使用HTTP_HOST识别标识先前主机名(Using HTTP_HOST to identify t

2019-10-18 16:23发布

我已经改变了我的域名我的网站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]

Answer 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]


文章来源: Using HTTP_HOST to identify the identify the previous host name