2013-03-02 54 views
0

寻找基于移动重定向htaccess的代码。该计划是让用户每24小时重新定向一个名为yyy.org的网站。的.htaccess重定向广告

我需要做的是检查它们是否满足移动标准。如果他们这样做,检查他们是否有cookie。如果两者都是真的,给他们一个cookie并将他们重定向到yyy.org网站。

的重写条件:

$RewriteCond %{HTTP_USER_AGENT} (mobile|android|blackberry|brew|cldc|docomo|htc|j2me|micromax|lg|midp|mot|motorola|netfront|nokia|obigo|openweb|opera.mini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|vodafone|wap|webos|windows.ce) [NC] 

其他可能的代码:这还没完:

RewriteBase/
RewriteEngine On 

# Check if mobile=1 is set and set cookie 'mobile' equal to 1 
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$) 
RewriteRule^- [CO=mobile:1:%{HTTP_HOST}:1440] 

# Check if mobile=0 is set and set cookie 'mobile' equal to 0 
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) 
RewriteRule^- [CO=mobile:0:%{HTTP_HOST}:1440] 

# cookie can't be set and read in the same request so check 
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) 
RewriteRule^- [S=1] 

# Check if this looks like a mobile device 
RewriteCond %{HTTP:x-wap-profile} !^$ [OR] 
RewriteCond %{HTTP_USER_AGENT} (mobile|android|blackberry|brew|cldc|docomo|htc|j2me|micromax|lg|midp|mot|motorola|netfront|nokia|obigo|openweb|opera.mini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|vodafone|wap|webos|windows.ce) [NC] 
RewriteCond %{HTTP:Profile}  !^$ 

# Check to make sure we haven't set the cookie before 
RewriteCond %{HTTP:Cookie}  !\mobile=0(;|$) 
# Now redirect to the mobile site 
RewriteRule^http://yyyy.com%{REQUEST_URI} [R,L] 

这是可能的,什么是剩余的代码?

回答

0

,如果他们是移动客户端可以将其重定向到本地脚本,然后检查脚本中的cookie,并根据cookie值行事,但作为用户我觉得很烦,我得到重定向到一个网页,我没有要求

也可以使用的RewriteCond饼干这样的:

RewriteEngine On 
RewriteBase/
RewriteCond %{HTTP_COOKIE} lang=([^;]+) [NC] 
RewriteRule ^(.*)$ /$1?lang=%1 [NC,L,QSA] 

Cookie以及htacces更多信息:http://www.askapache.com/htaccess/htaccess-fresh.html#Cookie_Manipulation_Tests_mod_rewrite

+0

我知道它的烦人,但是这就是我需要的 – MGParisi 2013-03-02 14:15:39