环境配置

使用apache的mod_rewrite模块为手机用户重定向

环境配置 2013-05-13

现在使用手机或平板电脑上网的用户越来越多。尤其对于手机用户来说,传统的ESPCMS网站显然不适合。专为手机用户定制一个合适的浏览界面也越来越普遍。

也由此涉及到如何判断用户的浏览终端类型的问题。本文介绍了如何使用apachemod_rewrite模块判断终端类型并重定向的方法。

 

前期准备:

1、开启mod_rewrite模块。

安装并开启apache的mod_rewrite模块。这里对于ESPCMS站长来说毋庸置疑都装了吧,笔者不再赘述^_^。

例如ESPCMS的WAP可以通过demo.ecisp.cn/wap/访问到手机版本的。

建立rewrite规则:

为网站建立rewrite规则,将手机用户定位到demo.ecisp.cn/wap/

vi /var/www/demo.ecisp.cn/web/.htaccess

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} “android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos” [NC]
RewriteRule ^$ http://demo.ecisp.cn/wap/ [L,R=302]
</IfModule>

对于demo.ecisp.cn/wap/的rewrite规则,如果不是手机用户访问demo.ecisp.cn/wap/的将用户重定位到主网站

vi /var/www/www.ecisp.cn/mobile/.htaccess

写入如下规则

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} “!(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)” [NC]
RewriteRule ^$ http://www.ecisp.cn/ [L,R=302]
</IfModule>

重启apache服务器后看看效果吧^_^

Enjoy It!

返回顶部

通过QQ联系我们

通过微信与我们联系

联系电话

在线留言

在线手册