How to do this in .htaccess?


I’m developing a mobile version of an existing site and need to forward mobile visitors entering from any given link to its equivalent on my mobile site. Example: Sending a mobile visitor to to

I know the best way to do this sitewide is using mod_rewrite, but I’m not very experienced with it.

I’m not worried about the mobile user detection end as I’ve got that part covered, but I can’t figure out how to redirect from* to* in all cases.

Does anyone else know what that part of the code would look like? Thank you!

Okay, this is what I’ve cobbled together so far. It’s not working - the main url redirects to the mobile subdomain, but deep links still aren’t redirecting (goal of the last line). What did I do wrong?

[code]# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

END WordPress

RewriteEngine on
RewriteBase /

prevent looping

RewriteCond %{HTTP_HOST} !^$

if the browser accepts these mime-types, it’s definitely mobile, or pretending to be

RewriteCond %{HTTP_ACCEPT} “text/vnd.wap.wml|application/vnd.wap.xhtml+xml” [NC,OR]

a bunch of user agent tests

RewriteCond %{HTTP_USER_AGENT} “sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera” [NC,OR]
RewriteCond %{HTTP_USER_AGENT} “mini|nitro|j2me|midp-|cldc-|netfront|mot|up.browser||audiovox”[NC,OR]
RewriteCond %{HTTP_USER_AGENT} “blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-”[NC,OR]
RewriteCond %{HTTP_USER_AGENT} “portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc”[NC,OR]
RewriteCond %{HTTP_USER_AGENT} “smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone/|wap1.|wap2.|iPhone|android”[NC]

rewrite rules here

RewriteRule .?{REQUEST_URI} [L,R=302][/code]

Try this?