Forum Moderators: phranque
It worked a few times and then nothing. Can someone help and let me know what I did wrong? and thanks ahead of time.
RewriteEngine on
#
# If mobile device UA or gif or PHP file
RewriteCond %{HTTP_USER_AGENT} !(Windows\ CE冰lackberry吉etFront同alm\ OS冰lazer划laine回WAP同lucker再vantGo) [NC,OR]
RewriteCond %{REQUEST_URI} \.(gif如hp)$
# skip next three rules
RewriteRule .* - [S=3]
#
# Rewrite mobile client requests for root directory only to mobiles subdirectory
RewriteRule ^([^/]*)$ /mobile/index.php [L]
#
# Force style id 7 for mobile clients, case one
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^(.+)&styleid=[0-9]+(.*)$
RewriteRule ^(mobile/.*) /index.php [L]
#
# Force style id 7 for mobile clients, case two
RewriteCond %{QUERY_STRING} !styleid=7[^0-9]*
RewriteCond %{QUERY_STRING} ^styleid=[0-9]+(.*)$
RewriteRule ^(mobile/.*) /index.php [L]
#
# Skip directive in the first rule lands here. Place additional rules
# (if any) for .gif files, .php files, and non-mobile user-agents here.
#
What should the result be?
What result do you actually get?
How does that differ from what you expected?
.
Please also note that none of that code is for a "redirect". They are all "rewrites".
Understanding the difference between a redirect (where the browser is told to make a new request for a different URL) and a rewrite (where the URL request is connected internally in the server to a different folder and/or filepath than might be expected from the requested URL, but the browser never gets to see what that path is) is very important.
What URL are you testing it with? www.example.com
What should the result be? www.example.com/mobile/index.php
What result do you actually get? when I type in www.example.com on my blackberry it does not redirect to /mobile/index.php
Strange I did have it working and I dont believe I changed anything,
Again thanks for the reply!
[edited by: jdMorgan at 2:54 am (utc) on Oct. 6, 2008]
[edit reason] No personal URLs, please. Use example.com [/edit]
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mobile/index.php
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml地pplication/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs地lav地lca地moi地udi地ste地van在enq在ird在lac在laz在rew圭ell圭ldc圭md-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang圬oco圯ric多ipt夷nno夷paq夸ava夸igs妄ddi妄eji奸eno奸g-c奸g-d奸g-g奸ge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui妃axo妃idp妃its妃mef妃obi妃ot-妃oto妃wbp好ec-好ewt好oki她pwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm如ana如ant如dxg如hil如lay如luc如ort如rox妁tek妁wap存age存ams存any" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-存ec-存end存eri存gh-存har存ie-存iem存mal存mar存ony存ph-存ymb宇-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli宇im-宇osh宇sm-守pg1守psi宅k-v宅oda安3cs安ap-安apa安api" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp安apr安ebc安inw安inw寺da寺da-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser守p.link安indowssce夷emobile妃ini妃mp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian妃idp安ap如hone如ocket妃obile如da如sp" [NC]
RewriteRule ^(.*)$ /mobile/index.php [L,R=302]
In this way you could probably reduce the length of this list -- as well as the need to constantly add new phone brands to it. The use of patterns matching very short "fragments" of the user-agent strings will likely lead to non-mobile devices being redirected to your mobile site, which is another reason to key off of things other than just the small bit of the UA string.
Jim