HTAccess重定向广告

问题描述 投票:0回答:1

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

我需要的是检查它们是否符合移动标准。如果他们这样做,请检查他们是否有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]

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

html .htaccess mobile
1个回答
0
投票

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

你也可以使用rewritecond这样的cookie:

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

有关cookies和htaccess的更多信息:qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.