Reputation: 1095
I successfully set up mobile redirect directory based on device but the client wants a link back 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 a .htaccess file with rewritengine off into the directory of the mobile website.
Any idea what rewrite conditions to use when both the mobile and main website use the same domain? Alternatively, would this be easier if I made a separate domain for the mobile website?
Upvotes: 4
Views: 422
Reputation: 27618
You could add another RewriteCond
to check for %{REQUEST_URI} !^/no-mobile/.*$
and then rewrite /no-mobile/
to /
. This will allow users on a mobile that want to view the full site to have a link to /no-mobile/
.
Alternative PHP Solution
If your client wants a way to allow mobile users to use both, you can use php. Do your same HTTP_USER_AGENT
check in PHP and redirect the user when the hit your site.
If they click a Full Site
button, you should redirect them to something like /force-desktop
where you set $_SESSION['no_mobile'] = true
. You can then incorporate this into your initial mobile check like so:
full-site.php:
<?php
session_start();
$_SESSION['no_mobile'] = true;
header('Location: /mobile');
die();
then a check when a page is loaded on your site (you'll have to do it on ever page, sadly):
if($is_mobile === true && !isset($_SESSION['no_mobile']){
header('Location: /mobile');
die();
}
Upvotes: 2