How to enable my mobile site to bypass mobile redirection?

I have successfully set up a device-based redirect directory for mobile devices, but the client wants the link to return to the full site.

RewriteEngine on Options +FollowSymlinks -MultiViews RewriteBase / RewriteCond %{HTTP_HOST} ^mysite.com$ [NC] RewriteCond %{REQUEST_URI} !^/mobile/.*$ RewriteCond %{HTTP_USER_AGENT} **{mobile dectection code I removed for this post}** RewriteRule ^(.*)$ /mobile/ [L,R=302] 

I put the .htaccess file with rewritengine in the directory of the mobile site.

Any idea what to rewrite the terms of use when both the mobile and primary website use the same domain? Alternatively, would it be easier if I made a separate domain for the mobile site?

+4
source share
1 answer

You can add another RewriteCond to check %{REQUEST_URI} !^/no-mobile/.*$ and then copy /no-mobile/ to / . This will allow users on a mobile device who want to view the full site to have a link to /no-mobile/ .

PHP alternative solution

If your client wants users to be able to use both users, you can use php. Do your same HTTP_USER_AGENT check in PHP and redirect the user when you put your site.

If they click the Full Site button, you should redirect them to something like /force-desktop , where you set $_SESSION['no_mobile'] = true . Then you can include this in your original mobile check, for example:

full site.php:

 <?php session_start(); $_SESSION['no_mobile'] = true; header('Location: /mobile'); die(); 

then check when the page is uploaded to your site (you will have to do this on the page, unfortunately):

 if($is_mobile === true && !isset($_SESSION['no_mobile']){ header('Location: /mobile'); die(); } 
+2
source

Source: https://habr.com/ru/post/1497136/


All Articles