简体   繁体   English

在移动网站上有一个链接,可绕过主网站上.htaccess文件的移动重定向

[英]Have a link on mobile website that bypasses the mobile redirect of a .htaccess file on a main website

I have 2 versions for one website. 一个网站有2个版本。 A normal website and a Jquery mobile website. 普通网站和Jquery移动网站。 I run one defaultrewite.php template and pull my content from a MYSQL database. 我运行一个defaultrewite.php模板,并从MYSQL数据库中提取内容。

I want to be able to put a link onto my mobile website that goes to the mainwebsite? 我希望能够将链接添加到我的移动网站上,该链接可以访问主网站吗?

Everytime I access the mainwebsite from a mobile device eg iphone, The .htaccess file sends me to the mobilewebsite. 每当我从移动设备(例如iphone)访问主网站时,.htaccess文件都会将我发送到该移动网站。

below is the code for my .htaccess file. 下面是我的.htaccess文件的代码。

Thanks 谢谢

RewriteEngine on
RewriteRule ^/?([a-z0-9-_]*)$ default-rewrite.php?page=$1 [L]
RewriteCond %{REQUEST_URI} !^http://sonae.co.za/.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera   mobile|palmos|webos|symbian|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobile.sonae.co.za/ [L,R=302]

Add a line above the second RewriteRule : 在第二个RewriteRule上方添加一行:

RewriteCond %{QUERY_STRING} !nomobile

You can then allow mobile devices to access the regular site by including this in the query string, eg 然后,您可以通过将其包含在查询字符串中来允许移动设备访问常规站点,例如

http://sonae.co.za/foo/bar?nomobile

This works by requiring that the string not be present in the query string 这通过要求查询字符串中不存在该字符串而起作用

Have the link go through a redirecter page, set a cookie called use_desktop if they click on that link: 让链接通过重定向器页面,如果他们单击该链接,请设置一个名为use_desktop的cookie:

$url = $_GET['redirect_url'];
setcookie('use_desktop', 1, time() + 60*60*24*30, '/');
header("Location: $url");
exit;

then add 然后加

RewriteCond %{HTTP:Cookie} !(^|;\ *)use_desktop=([^;\ ]+)

as another condition before the rewrite rule. 作为重写规则之前的另一个条件。

This will be better than the query string as once that query string is gone (ie they click on a link) they will be redirected back to the mobile version, this lets them continue to be on the desktop version until they click on a "use mobile link", which would go through a redirecter and remove that cookie. 这将比查询字符串更好,因为一旦查询字符串消失(即,他们单击链接),它们将被重定向回移动版本,这使它们继续使用桌面版本,直到他们单击“使用”为止。移动链接”,它将通过重定向器并删除该Cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM