Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Thanks,

Arun S

share|improve this question
add comment

1 Answer

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. xkcd.com/869 –  Kevin M Feb 27 '12 at 19:52
add comment

Your Answer

 
discard

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.