Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have issues in setting up the htaccess rules to redirect my to the inner pages in mobile. I want to redirect all pages in my website to get redirected to mobile site when accessing through a mobile device.

What is working is : Redirect index page correctly in mobile devices.

What is not working is : If we take http://MY-SITE/Contact-Us page in mobile device, it is going to the actual site. We need to go to mobile device homepage in this scenario.

Here is the htaccess file we are currently using:

#Redirect Mobile Users
RewriteCond %{REQUEST_URI} !^/Mobile-Landing-Page/.*$
# 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|up\.link|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]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /Mobile-Landing-Page/ [L,R=302]

I have experimented many rules but the output was a failure.

If any one have an idea about how it will implement. Please share.


Arun S

share|improve this question
up vote 1 down vote accepted

Your RewriteRule uses the expression ^$ as the URL pattern to match - this pattern means "start-of-string immediately followed by end-of-string with nothing in between". In your example, the request would come in as [start-of-string]Contact-Us[end-of-string], which would not match the pattern as there is something between start and finish.

If you want to redirect everyone to the mobile landing page, the pattern in the RewriteRule will need a section meaning "match any number of characters" - so like the following:

RewriteRule ^(.*)$ /Mobile-Landing-Page/ [L,R=302]

[Incidentally, as a mobile device user I find "mobile landing pages" really annoying, and would rather be redirected to the mobile version of the page I requested. But I appreciate that's often much harder to do.]

share|improve this answer
+1 for the incidental note about mobile landing pages. – Kevin M Feb 27 '12 at 19:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.