apache.htaccessmobile

Using htaccess to redirect to mobile version unless user wants to "force desktop version"


I have the following .htaccess file to redirect to the mobile version of my site:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://www.example.com/mobile [L,R=302]

However, I need to add a condition for mobile users to be able to request the desktop site.

I've searched around a bit and haven't found a simple answer. I just need to have an URL such as http://www.example.com/?desktop to avoid the redirection to /mobile.


Solution

  • Try that:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} !^desktop
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos" [NC]
    RewriteRule ^$ http://www.example.com/mobile [L,R=302]