Forum Moderators: phranque

Message Too Old, No Replies

Redirect

Need help

         

Keith

10:57 pm on Oct 5, 2008 (gmt 0)

10+ Year Member



I found this script here and I have something wrong, It does not redirect to my mobile page.
I have placed the script inside my htaccess file on my root dirictory of hosting provider. /public_html

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.
#

g1smd

11:14 pm on Oct 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What URL are you testing it with?

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.

Keith

11:39 pm on Oct 5, 2008 (gmt 0)

10+ Year Member



Thanks g1smd

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]

g1smd

11:46 pm on Oct 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It cannot, and will not, ever "redirect".

The code you have is for a "rewrite".

.

Some improvements:

^(mobile/.*)
can be recoded as
^mobile/

The

(.*)$
on the end of a condition means nothing, so it can be removed.

[edited by: g1smd at 11:51 pm (utc) on Oct. 5, 2008]

Keith

11:50 pm on Oct 5, 2008 (gmt 0)

10+ Year Member



Ok, how did it work the first few times? Worked great and then notta?
And is there a code that I am looking for?

Thanks Again!

Keith

10:33 am on Oct 6, 2008 (gmt 0)

10+ Year Member



If anyone else is look for the code. This works great

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]

jdMorgan

2:22 pm on Oct 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to look at that the actual user-agent strings for the devices represented on that list, and see which of them share common traits. For example, many of them will use the same mobile browser, and many of them will have "Profile/MIDP-2.0 configuration/CLDC-1.1" and/or "UP.Link/6.3.0.0.0" or "Windows CE" in them, start with "WAP" etc.

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