RewriteCond - ignore real dirs

Apr 2, 2009 at 9:21 PM
Pulling my hair out here.

IIRF 1.2.13, IIS 6

I'm trying to interject a Condition to only rewrite if the incoming URL is NOT a file or directory. I've tried several other Server Variables to no avail. Maybe I'm just missing something stupid.

I have a physical directory - /enews/ - that I need the following rule to ignore.

So if the incoming URL is /enews/ I don't want the rule to fire. I'm trying to avoid hard coding rules for physical folders but for the life of me, i can't get the !-f or !-d to hook it.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([\w-]+)/(?:(\d+)/)?(?:[^/]*/)?$ /_pages/default.asp?sctn=$1&id=$2 [I,L]


-------------------------
TestDriver ouput:

--------------------------------------------
Thu Apr 02 16:19:43 2009 - Ionic URL Rewriting ISAPI Filter v1.2.13
Thu Apr 02 16:19:43 2009 - Initialize,  main threadId= 4148
Processing URLs...(SampleUrls.txt)

Thu Apr 02 16:19:43 2009 - ApplyRules (depth=0)
Thu Apr 02 16:19:43 2009 - Rule 1 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 2 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 3 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 4 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 5 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 6 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 7 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 8 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 9 : -1 (No match)
Thu Apr 02 16:19:43 2009 - Rule 10 : 2 matches
Thu Apr 02 16:19:43 2009 - ReplaceServerVariables: InputString='%{PATH_TRANSLATE
D}' out='%{PATH_TRANSLATED}'
Thu Apr 02 16:19:43 2009 - GenerateReplacementString: src='/enews/','(null)' Rep
lacePattern='%{PATH_TRANSLATED}' vec=[[  [  0, 7, 1, 6] [] ] counts=2,0
Thu Apr 02 16:19:43 2009 - EvaluateCondition: checking '%{PATH_TRANSLATED}' agai
nst pattern '!-f'
Thu Apr 02 16:19:43 2009 - EvaluateCondition: cond->SpecialConditionType= 'f'
Thu Apr 02 16:19:43 2009 - EvaluateCondition: Special: it is not a file; not a d
irectory
Thu Apr 02 16:19:43 2009 - EvaluateCondition: Special, retVal= True
Thu Apr 02 16:19:43 2009 - Cond : Child is non NULL
Thu Apr 02 16:19:43 2009 - Cond : Current condition evaluates to TRUE
Thu Apr 02 16:19:43 2009 - Cond : Logical AND, ergo we evaluate the Child
Thu Apr 02 16:19:43 2009 - ReplaceServerVariables: InputString='%{PATH_TRANSLATE
D}' out='%{PATH_TRANSLATED}'
Thu Apr 02 16:19:43 2009 - GenerateReplacementString: src='/enews/','(null)' Rep
lacePattern='%{PATH_TRANSLATED}' vec=[[  [  0, 7, 1, 6] [] ] counts=2,0
Thu Apr 02 16:19:43 2009 - EvaluateCondition: checking '%{PATH_TRANSLATED}' agai
nst pattern '!-d'
Thu Apr 02 16:19:43 2009 - EvaluateCondition: cond->SpecialConditionType= 'd'
Thu Apr 02 16:19:43 2009 - EvaluateCondition: Special: it is not a file; not a d
irectory
Thu Apr 02 16:19:43 2009 - EvaluateCondition: Special, retVal= True
Thu Apr 02 16:19:43 2009 - Cond : Child is NULL
Thu Apr 02 16:19:43 2009 - EvaluateConditionList: TRUE, Rule will apply
Thu Apr 02 16:19:43 2009 - ReplaceServerVariables: InputString='/_pages/default.
asp?sctn=$1&id=$2' out='/_pages/default.asp?sctn=$1&id=$2'
Thu Apr 02 16:19:43 2009 - GenerateReplacementString: src='/enews/','(null)' Rep
lacePattern='/_pages/default.asp?sctn=$1&id=$2' vec=[[  [  0, 7, 1, 6] [] ] coun
ts=2,0
Thu Apr 02 16:19:43 2009 - GenerateReplacementString: replacing ($1) with enews
Thu Apr 02 16:19:43 2009 - WARNING: GenerateReplacementString: Substring index o
ut of range ($2)
Thu Apr 02 16:19:43 2009 - Result (length 34): /_pages/default.asp?sctn=enews&id
=
Thu Apr 02 16:19:44 2009 - Last if Match
Thu Apr 02 16:19:44 2009 - ApplyRules: returning 1

REWRITE '/enews/' ==> '/_pages/default.asp?sctn=enews&id='

Thu Apr 02 16:19:44 2009 - ApplyRules (depth=0)
Thu Apr 02 16:19:44 2009 - Rule 1 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 2 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 3 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 4 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 5 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 6 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 7 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 8 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 9 : -1 (No match)
Thu Apr 02 16:19:44 2009 - Rule 10 : 2 matches
Thu Apr 02 16:19:44 2009 - ReplaceServerVariables: InputString='%{PATH_TRANSLATE
D}' out='%{PATH_TRANSLATED}'
Thu Apr 02 16:19:44 2009 - GenerateReplacementString: src='/markets/','(null)' R
eplacePattern='%{PATH_TRANSLATED}' vec=[[  [  0, 9, 1, 8] [] ] counts=2,0
Thu Apr 02 16:19:44 2009 - EvaluateCondition: checking '%{PATH_TRANSLATED}' agai
nst pattern '!-f'
Thu Apr 02 16:19:44 2009 - EvaluateCondition: cond->SpecialConditionType= 'f'
Thu Apr 02 16:19:44 2009 - EvaluateCondition: Special: it is not a file; not a d
irectory
Thu Apr 02 16:19:44 2009 - EvaluateCondition: Special, retVal= True
Thu Apr 02 16:19:44 2009 - Cond : Child is non NULL
Thu Apr 02 16:19:44 2009 - Cond : Current condition evaluates to TRUE
Thu Apr 02 16:19:44 2009 - Cond : Logical AND, ergo we evaluate the Child
Thu Apr 02 16:19:44 2009 - ReplaceServerVariables: InputString='%{PATH_TRANSLATE
D}' out='%{PATH_TRANSLATED}'
Thu Apr 02 16:19:44 2009 - GenerateReplacementString: src='/markets/','(null)' R
eplacePattern='%{PATH_TRANSLATED}' vec=[[  [  0, 9, 1, 8] [] ] counts=2,0
Thu Apr 02 16:19:44 2009 - EvaluateCondition: checking '%{PATH_TRANSLATED}' agai
nst pattern '!-d'
Thu Apr 02 16:19:44 2009 - EvaluateCondition: cond->SpecialConditionType= 'd'
Thu Apr 02 16:19:44 2009 - EvaluateCondition: Special: it is not a file; not a d
irectory
Thu Apr 02 16:19:44 2009 - EvaluateCondition: Special, retVal= True
Thu Apr 02 16:19:44 2009 - Cond : Child is NULL
Thu Apr 02 16:19:44 2009 - EvaluateConditionList: TRUE, Rule will apply
Thu Apr 02 16:19:44 2009 - ReplaceServerVariables: InputString='/_pages/default.
asp?sctn=$1&id=$2' out='/_pages/default.asp?sctn=$1&id=$2'
Thu Apr 02 16:19:44 2009 - GenerateReplacementString: src='/markets/','(null)' R
eplacePattern='/_pages/default.asp?sctn=$1&id=$2' vec=[[  [  0, 9, 1, 8] [] ] co
unts=2,0
Thu Apr 02 16:19:44 2009 - GenerateReplacementString: replacing ($1) with market
s
Thu Apr 02 16:19:44 2009 - WARNING: GenerateReplacementString: Substring index o
ut of range ($2)
Thu Apr 02 16:19:44 2009 - Result (length 36): /_pages/default.asp?sctn=markets&
id=
Thu Apr 02 16:19:44 2009 - Last if Match
Thu Apr 02 16:19:44 2009 - ApplyRules: returning 1

REWRITE '/markets/' ==> '/_pages/default.asp?sctn=markets&id='

DllMain
Thu Apr 02 16:19:44 2009 - DllMain PROCESS_DETACH

Jun 12, 2009 at 7:32 PM

Figured it out - I think.

I'm not sure if this is related to the version but the test was with the latest version of IIRF.

I was having a problem trying to make IIRF ignore URL's that were found in an actual path but rewrite those that weren't.

After some experimenting, I found that when using the latest version, you need to ensure that the server variable is in UPPER CAPS - although the manual does not explicitly specify that fact.

This is on IIS 6.

I also found that when writing a RediretRule you also need to specify the [R=30X] modifier, otherwise it doesn't update the URL. (also not explicit in the manual).