homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

htaccess for mobile redirect issue

 2:52 pm on Jan 28, 2011 (gmt 0)

I have been racking my brain trying to redirect mobile phone visitors to my mobile website except for a request for a specific file pattern.

The problem is that upon refresh of the browser it momentarily goes out to the mobile site but then returns to the main site.

I viewed the headers with "Live HTTP headers" and it is indeed going out to the mobile site.

The redirect works fine without the "REQUEST_URI" line.

Here is the htaccess code I am using: (again it sort of works but not the way it should)

# Mobile Redirects
RewriteCond %{HTTP_USER_AGENT} android|blackber|htc|phone|mobile [NC]
RewriteCond %{REQUEST_URI} !^(/examplefile)
RewriteRule ^(.*)$ [mobile.example.com...] [R,L]





 3:53 pm on Jan 28, 2011 (gmt 0)

RewriteCond %{HTTP_USER_AGENT} android|blackber|htc|phone|mobile [NC]

Is this a typo?
OR's require enclosure in parentheses.

RewriteCond %{HTTP_USER_AGENT} (android|blackber|htc|phone|mobile) [NC]


 6:14 pm on Jan 28, 2011 (gmt 0)

Wilderness thanks for the reply.

I just tried putting the parentheses and it made no difference.

I have been running without the parentheses for months with no problems.

There must be a missing conditional statement somewhere.


 6:18 pm on Jan 28, 2011 (gmt 0)

RewriteRule ^(.*)$ [mobile.example.com...] [R,L]

Did you leave off the 302 intentionally?

RewriteRule ^(.*)$ [mobile.example.com...] [R=302,L]

BTW, if you've been running absent the parentheses?
I'm inclined to believe your were just catching the first term and none of the rest. Jim or gm1 may expand.


 6:47 pm on Jan 28, 2011 (gmt 0)

I left off the "302" to keep the file size small...the "R" flag on its own implies a "302".


 9:56 pm on Jan 28, 2011 (gmt 0)

Well, I am happy to report that the problem has been fixed.

The problem was that I was excluding the html file but not the corresponding css file. Thus when the browser requested the html file, the server redirected properly based on the rules but when the request came for the css file the name didn't match the exclusion and it had to fetch the matching css from the mobile site thus breaking up the formatting.

I just renamed the css file the same name of the html and problem fixed. I could also have just added another exclusion but felt renaming the css file was simpler.


 11:19 pm on Jan 28, 2011 (gmt 0)

foo|bar|that is fine on its own.

You need parentheses if there are other elements in the pattern:
(foo|bar|that)something or if there is any anchoring at either end.
Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved