Forum Moderators: phranque

Message Too Old, No Replies

how to write condition for default index

         

foofoocheese

10:49 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Hi there,

Working on a mobile phone sniffer -
I'm trying to catch default page requests for the directory that my .htaccess file is located within, but I dont want to catch all requests to images etc, which is happening with my current rules below.. So for example I want to catch requests for [localhost...] but not [localhost...] Basically needs to exactly match the current directory without hard coding of urls if possible..

RewriteCond %{HTTP_USER_AGENT} ^(Nokia¦SonyEricsson¦BlackBerry¦SymbianOS¦MOT¦SEC¦Mini) [NC]

RewriteCond %{THE_REQUEST} ^$ [NC] # this needs to only catch requests for the current folders default page and not catch requests for style sheets, images etc..

RewriteRule ^(.*)$ index.php?mobile=$1 [QSA,L]

jdMorgan

12:08 am on Aug 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following should be all you need. I assume you want to pass the phone's user-agent substring as the value for "mobile=", and that you expect additional query name/value pairs to be passed for these requests (if not, you don't need "QSA,") :

RewriteCond %{HTTP_USER_AGENT} ^(Nokia¦SonyEricsson¦BlackBerry¦SymbianOS¦MOT¦SEC¦Mini) [NC]
RewriteRule ^$ index.php?mobile=%1 [QSA,L]

[added] Replace the broken pipe "¦" characters above with solid pipes before use; Posting on this forum modifies the pipe characters. [/added][1]

Jim

[1][edited by: jdMorgan at 12:09 am (utc) on Aug. 29, 2008]

foofoocheese

12:31 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Great thanks for that jd works a treat!

jdMorgan

12:41 am on Aug 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My only concern would be that you have the pattern start-anchored, which means that the user-agent must *start* with Nokia, SonyEricsson, etc. While this is true for many of those devices, "SymbianOS" is usually out in the middle, since it's the OS, and not the device.

In some cases, you're better off looking for generic stuff like "Profile/MIDP-[0-9.]+\ configuration/CLDC-[0-9.]+" instead of trying to nail down specific devices at the mod_rewrite level. If you haven't been supporting mobile devices for very long, you're about to learn that their user-agent strings are a total mess -- The makers don't follow the standards for defining user-agent strings, and even change their own "standard" between their own makes and models! Good luck - I'm still trying to figure them out myself.

Jim

foofoocheese

12:58 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Yeah I had a quick look through some listings of the user agents used by mobiles - and I have to agree - its a complete mess. Just using this a quick proof of concept so I will be narrowing down the supported phones in any production release.

Standards hehe classic..

Thanks again