I have a site that can allow me to access the mobile version of the site via a query in the URL.
What I can’t figure out is how to automatically redirect mobile users to this version (currently you have to add ‘?useformat=mobile’ in order to view).
This is my current htaccess setup
RewriteEngine On
#MediaWiki short URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#Mobile - not working?
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^([^/]*)$ /index.php?useformat=mobile&title=$1 [L]
#HTTPS redirect (site uses HTTPS)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Kinda new to mod_rewrite, not done much with it before.
You need to add this above your mobile rule:
And you need to move your mobile rules above the mediawiki rules because it’s rewriting before the mobile rules get applied, and then you need to move the HTTPS rules above that. So together, it should look something like this: