使用HTTP_HOST识别标识previous主机名 [英] Using HTTP_HOST to identify the identify the previous host name

查看:97
本文介绍了使用HTTP_HOST识别标识previous主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经改变了我的网站test.com我的域名test2.com

test.com改为test2.com

域名

 我想知道,如果像test.com/*所有的页面将被重定向到test2.com/*~~V
 

在test2.com,我写这封信的mod_rewrite识别智能移动设备重写规则。

 对于所有智能手机,我想请求重定向test.com/*到test2.com(主页)

对于每一个非智能手机,我想重定向test.com/*到test2.com/*~~V
 

我研究了下列条件这一点。我不知道这是否是正确与否。

我已经尝试了一些事情是这样的。

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^测试\ .COM $ [和]
的RewriteCond%{HTTP_USER_AGENT}移动
的RewriteCond%{HTTP_USER_AGENT}!(安卓|黑莓| iPhone | iPod的| Windows手机)[NC]
重写规则^(。*)$ http://test2.com/mobil/#1 [L]
 

解决方案

启用的mod_rewrite 的.htaccess 的httpd.conf ,然后把这个code在 DOCUMENT_ROOT /的.htaccess 文件:

 选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /

#对于移动设备:
的RewriteCond%{HTTP_HOST} ^(WWW \)?测试\ .COM $ [NC]
的RewriteCond%{HTTP_USER_AGENT}(安卓|黑莓| iPhone | iPod的| Windows手机)[NC]
重写规则^ http://test2.com/ [L,R = 301]

#对于非移动设备:
的RewriteCond%{HTTP_HOST} ^(WWW \)?测试\ .COM $ [NC]
重写规则^(。*)$ http://test2.com/$1 [L,R = 301]
 

I have changed my Domain name of my site test.com to test2.com

Domain name changed from test.com to test2.com

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

In test2.com, I am writing the rewrite rule in mod_rewrite to identify the smart mobile device.

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/*

I have researched the following condition for this. I am not sure if this is correct or not.

I have tried some thing like this.

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]

解决方案

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

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]

这篇关于使用HTTP_HOST识别标识previous主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆