RewriteCond !-f on IIS7.5

Topics: User Forum
Sep 22, 2011 at 5:24 PM
Edited Sep 22, 2011 at 5:25 PM

I'm getting this weird behavior in IIRF only on IIS7.5: RewriteCond %{REQUEST_FILENAME} !-f doesn't work. It fails to detect an existing file, so it matches the rule when it shouldn't.

I tried the exact same configuration on two IIS7.5 boxes (one Windows 2008 R2 x64, another Windows 7 x64) and it fails.

I also tried it on two IIS6 boxes (Windows 2003 x86, Windows 2003 x64) and it works as expected.

This is with IIRF

Has anyone seen this?


Sep 23, 2011 at 2:03 PM

I turned logging to the max and I see an "invalid path" message when evaluating the condition:

EvalCondition: t(REQUEST_FILENAME) op(f) p(!-f)
EvalCondition: cond->SpecialConditionType= 'f'
EvalCondition: Special: invalid path.
EvalCondition: Special variant, retVal= false
EvalCondition: Cond t(%{REQUEST_FILENAME}) op(f) p(!-f) => TRUE

Sep 23, 2011 at 2:54 PM
Edited Sep 23, 2011 at 3:00 PM

I added the path to that "invalid path" logging line and got:

EvalCondition: Special: invalid path: REQUEST_FILENAME

I also see:

GetServerVariable: getting 'REQUEST_FILENAME'
GetServerVariable: special variable name
GetServerVariable: 16 bytes
GetServerVariable: result 'REQUEST_FILENAME'

So it seems that REQUEST_FILENAME isn't being correctly resolved... Any ideas?

Sep 23, 2011 at 3:29 PM

I finally managed to work around this by using PATH_TRANSLATED instead of REQUEST_FILENAME, however this works on IIS7 but not IIS6.

It also worked using REQUEST_URI as explained in this thread but it required me to hardcode the app path.

For some reason REQUEST_FILENAME and REQUEST_URI aren't even on the table of IIS server variables.

Sep 26, 2011 at 5:18 AM
Edited Sep 26, 2011 at 5:18 AM

Right - check the documentation for IIRF - those are not "real" IIS Server variables. They are synthetic, IIRF makes up the value.  It tries to do the right thing but it may not always be what you expect.

You should be able to see what's happening pretty clearly in the IIRF logs.

Sep 26, 2011 at 1:18 PM

Thanks, I just found it in the docs... however, if PATH_TRANSLATED is not the same as REQUEST_FILENAME and I don't have REQUEST_FILENAME in IIS7.5, what should I use? Is it safe to use PATH_TRANSLATED anyway? And is there any way I can get the same config working both in IIS6 and IIS7.5 ?

Thanks again for IIRF!


Oct 2, 2011 at 9:59 PM

Hi Mauricio, I don't know what you mean by "safe".  If it works, it works.

As for whether you can get the same config working in IIS6 and 7, you will have to test to make sure.  I don't know the answer to that.  It depends on the rules you use, the requests that come in, and so on.  You have to test.



Oct 4, 2011 at 10:30 PM

Ok, just wanted to check if you knew something more about this, maybe there was a general solution.

I guess I'll just try to upgrade everything to IIS 7.5 as soon as possible.

Thanks again.