redirect based on http_user_agent fails

Topics: Developer Forum, User Forum
Dec 17, 2010 at 5:35 PM

I have the following rule defined:

RewriteCond  %{HTTP_USER_AGENT} iPhone|iPod|blackberry|android|windows+ce [OR] 
RewriteCond  %{USER_AGENT} Mobile
RedirectRule  ^(/)$ http://www.conklincarshutchinson.mobi [L]

It appears to parse okay:

Fri Dec 17 11:31:20 -  6080 - LogFile re-opened.
Fri Dec 17 11:31:23 -  6080 - AwaitIniChangeAndReinit: Detected change in the  ini file 'D:\Inetpub\ISAPI Rewrite Settings\Conklin Cars\IsapiRewrite4.ini'
Fri Dec 17 11:31:23 -  6080 - AwaitIniChangeAndReinit: Ionic ISAPI Rewriting Filter (IIRF) v1.2.16 R5
Fri Dec 17 11:31:23 -  6080 - ReadConfig
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line 1: RewriteLogLevel 3
Fri Dec 17 11:31:23 -  6080 - ReadConfig: setting LogLevel to 3
Fri Dec 17 11:31:23 -  6080 - LogFile re-opened.
Fri Dec 17 11:31:23 -  6080 - ReadConfig: new log file name: 'D:\Inetpub\ISAPI Rewrite Logs\279-Conklin Cars\log09.3572.log'
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line 4: IterationLimit 3
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line 5: StatusUrl /iirfStatus
Fri Dec 17 11:31:23 -  6080 - ReadConfig: StatusUrl is enabled for local requests only.
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line  10: RewriteCond %{HTTP_USER_AGENT}                             iPhone|iPod|blackberry|android|windows+ce 
Fri Dec 17 11:31:23 -  6080 - ParseCondModifierFlags: '[OR]'
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line  11: RewriteCond %{USER_AGENT}                                  Mobile                                    
Fri Dec 17 11:31:23 -  6080 - ReadConfig: line  12: RedirectRule (rule 1)  '^(/)$'  'http://www.conklincarshutchinson.mobi'      [L]
Fri Dec 17 11:31:23 -  6080 - ReadConfig: Done reading, found 1 rules (0 errors, 0 warnings) on 13 lines

And according to the log, it appears to work:

Fri Dec 17 11:31:23 -  6080 - LogFile re-opened.
Fri Dec 17 11:31:26 -  5496 - HttpFilterProc: SF_NOTIFY_URL_MAP
Fri Dec 17 11:31:26 -  5496 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Fri Dec 17 11:31:26 -  5496 - DoRewrites
Fri Dec 17 11:31:26 -  5496 - DoRewrites: Url: '/'
Fri Dec 17 11:31:26 -  5496 - EvaluateRules: depth=0
Fri Dec 17 11:31:26 -  5496 - EvaluateRules: Rule 1 : 2 matches
Fri Dec 17 11:31:26 -  5496 - EvalCondition: ts1 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
Fri Dec 17 11:31:26 -  5496 - ApplyCaseConversion: after  'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'
Fri Dec 17 11:31:26 -  5496 - EvalCondition: checking 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16' against pattern 'iPhone|iPod|blackberry|android|windows+ce'
Fri Dec 17 11:31:26 -  5496 - EvalCondition: match result: 1 (match)
Fri Dec 17 11:31:26 -  5496 - EvalCondition: returning TRUE
Fri Dec 17 11:31:26 -  5496 - EvalConditionList: rule 1, TRUE, Rule will apply
Fri Dec 17 11:31:26 -  5496 - ApplyCaseConversion: after  'http://www.conklincarshutchinson.mobi'
Fri Dec 17 11:31:26 -  5496 - EvaluateRules: Result (length 37): http://www.conklincarshutchinson.mobi
Fri Dec 17 11:31:26 -  5496 - EvaluateRules: Last Rule
Fri Dec 17 11:31:26 -  5496 - EvaluateRules: returning 1
Fri Dec 17 11:31:26 -  5496 - DoRewrites: Rewrite Url to: 'http://www.conklincarshutchinson.mobi'

However, the browser never rediects that I can see. It hits the normal site's 404 page. What should I be doing differently?

Thanks!

 

Coordinator
Dec 17, 2010 at 5:58 PM
Edited Dec 17, 2010 at 6:00 PM

Hmmm....

the log looks strange.  Your rule says "Redirect" but when it fires, IIRF is *rewriting*. 

To workaround the problem, I'd suggest either (a) removing the [L] on your rule, or (b) removing the [L] and replacing it with an explicit [R=3xx] modifier.

The [L] doesn't work with Redirect.  It really makes sense only for rewrites.  IIRF should generate a warning in the LOG file if these are present together. Yours doesn't show any such warning.  Odd.

You don't say what version of IIRF you're using.  You're using an out-of-date version of IIRF. Version 1.2 is no longer maintained or updated. I recall that at one time there was a bug relating to this.  But it's been fixed for a long time in IIRF v2. You should be using IIRF v2.

the workaround I suggested above may yet work for you. But you'll encounter other problems if you don't update to the current IIRF.

 

Dec 17, 2010 at 10:15 PM

Yes - I'm using 1.2. The update process on Windows Server 2003 to version 2.1 was so painful I gave it up and reverted back.

Thanks for the suggestion. Trying it now. If that doesn't work, I'll handle my redirection programatically and upgrade when/if the daily schedule lightens up.