Welcome to WebmasterWorld Guest from 54.145.221.99

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

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]


Thanks,

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

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.