Permalink and secondery mobile site

3 posts by 1 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 11, 2015   (RSS)

By Twocans - May 5, 2015 - edited: May 6, 2015

OK I still have not worked out permalink but I have managed to get code below which works for me as I have tested it on 4 different phones and about 6 different computers lol.

See I was also worried how to redirect from a mobile site to the desktop version, as I did not want my site visitors to get to my mobile site via pc.

I still have not managed to get my permalink working on the mobile site anyway

the htaccess code is below and it works for me on hostgator 2015.

K

Redirect desktop users away from mobile site with .htaccess

#######################################################################################
# This .htaccess redirect desktop users away FROM mobile site with .htaccess 2015
# Don't forget replace instances of [example.com] in code below with your domain name.
# START
#######################################################################################

RewriteEngine On

RewriteCond %{HTTP_HOST} ^m\. [NC]
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera\smobile|palmos|webos) [NC]
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=302]

#######################################################################################
# The above .htaccess redirect desktop users away FROM mobile site with .htaccess
# FINISH
#######################################################################################

Above is for redirecting desktop users to mobile

Below is for redirecting desktop users to mobile


#######################################################################################
# This .htaccess file redirects mobile browsers and devices to an alternate destination
# Don't forget replace instances of [example.com] in code below with your domain name.
# START
#######################################################################################

# Ensure rewriting is on
RewriteEngine On

# Check for redirect param
RewriteCond %{QUERY_STRING} ^.*redirect=true.*
RewriteRule ^(.*)$ - [co=gomobi_prevent_redirect:false:.[example.com]:0:/]

RewriteCond %{QUERY_STRING} ^.*redirect=false.*
RewriteRule ^(.*)$ - [co=gomobi_prevent_redirect:true:.[example.com]:7200:/]


RewriteCond %{HTTP_COOKIE} !gomobi_prevent_redirect=true [OR]
RewriteCond %{QUERY_STRING} ^.*redirect=true.*

# Don't redirect if its false
RewriteCond %{QUERY_STRING} !^.*redirect=false.*

# Prevent loops
# RewriteCond %{HTTP_HOST} !^m.[example.com]$

# Exclude certain paths e.g. cpanel admin etc.
RewriteCond %{REQUEST_URI} !(.*)cpanel(/?)$
RewriteCond %{REQUEST_URI} !^/wp-(.*)$
RewriteCond %{REQUEST_URI} !/xmlrpc.php

# Exclude certain extensions e.g. images, docs etc
RewriteCond %{REQUEST_URI} !(.*).(?i:jpg|jpeg|webp|gif|bmp|png|js|css|txt|pdf|doc|docx|xls|xlsx|rar|zip|7z|mpg|mp4|mpeg|divx|avi|ogv|webm|mp3|ogg|wav|aac)

# Switch based on significant accept headers
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]


# Specific devices/mandufacturers
RewriteCond %{HTTP_USER_AGENT} "iphone|ipad|ipod|android|nokia|ios|opera m(ob|in)i|iemobile|symbian|samsung|sec-|htc|huawei|ericsson|sonyericsson|blackberry|motorola|sagem|kyocera|zte|kddi|docomo|j-phone|kwc|lenovo|lg|mot|softbank|nec|audiovox|alcatel|sharp|sie-|sanyo|sendo|amoi|xda|bird|benq|palm|pantech|panasonic|fly|asus-|baiduispider|googlebot-mobile|nintendo|psp|dalvik|windows ce|foma|brew|webos|fennec|netfront|teleca|obigo|vodafone|up.browser|portalmmm" [NC]

RewriteRule ^(.*)$ http://m.[example.com] [L,R=302]
#### END GoMobi Redirect Settings ####

#######################################################################################
# This .htaccess file redirects mobile browsers and devices to an alternate destination
# FINISH
#######################################################################################

By Twocans - May 11, 2015

It seems Permalinks does not work so easy with a separate mobile site, and due to the response I have received I will end up no longer using permalinks and doing it myself in the htaccess file.

regards

Kenny