How to Redirect Mobile Traffic to Your goMobi Website

goMobi will redirect your site traffic to the mobile subdomain of your main domain (m.example.com) whenever a mobile device is detected by default. This happens automatically when you setup your goMobi website.

However, there are times when this functionality may not work. When this occurs, it is possible that the functionality is broken or has been intentionally removed. If either of these is the case, you can restore the redirect functionality in two ways.

Automatic Restore

  1. Log into your cPanel.
  2. Select the goMobi icon from the Software/Services section.
  3. Select the mobile website that is having redirect issues.
  4. Underneath the phone example of your mobile website, click the Finish button. This will automatically generate the .htaccess codes necessary to redirect your mobile website. The following screen will allow you to select the scripting language of your desktop website, and will generate the necessary code to ensure that visitors to your desktop website are properly redirected.
  5. From the dropdown menu for your site, select the correct language.
  6. Click Generate to get the correct code for your website.
  7. The generator will provide you with instructions on how to implement the code provided.

Manual Restore

  1. Log into your cPanel.
  2. Under the Files section, select File Manager.
  3. In the popup window, select the website you wish to modify from the dropdown box and click Go.
  4. locate your .htaccess file.
  5. Right click on the file and select Code Edit.
  6. If there are any directives already in the file, you will want to disable them by typing a "#" in front of them.
    • Alternatively, you can simply rename the .htaccess file and start fresh with a blank .htaccess. 
    • Copy and paste the code below into the .htaccess file to re-enable the default goMobi redirects.
To ensure that this code works properly for your website, please replace the four instances of [example.com] in the code below with your domain name. For your convenience these are marked in bold.

Example Code

Note: Some of the text below has been word-wrapped. For best results, copy and paste the whole block of code to ensure proper formatting.

#### BEGIN GoMobi Redirect Settings ####
#######################################################################################
# This .htaccess file redirects mobile browsers and devices to an alternate destination
#
#######################################################################################

 

# 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 ####

Color coding of code is added for readability and is not actually part of the code.