Reputation: 5349
I'm using Iirf v2.0.
I have the following directory structure:
/
/library
/library/index.php
/webroot
/webroot/images
/Iirf.ini
Where I have a library folder which contains my application, a webroot folder (which contains images, stylesheets etc) and an Iirf.ini config file.
I'm wanting to redirect all requests to /library/index.php if the file doesn't exist under webroot.
eg:
Request Response
/images/blah.png -> /webroot/images/blah.png
/news -> /library/index.php
My Iirf.ini config has:
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /library/index.php [L]
Which redirects everything to /library/index.php
but I'm having trouble working out how to check if the REQUEST_FILENAME
exists under webroot.
I've looked at this question but I don't have access to DOCUMENT_ROOT
. It gives me the following (taken from the log):
Thu Jul 15 11:46:21 - 760 - ReplaceServerVariables: VariableName='REQUEST_FILENAME' Value='C:\web\favicon.ico'
Thu Jul 15 11:46:21 - 760 - ReplaceServerVariables: in='%{DOCUMENT_ROOT}/webroot/%{REQUEST_FILENAME}' out='DOCUMENT_ROOT/webroot/C:\web\favicon.ico'
Any help would be greatly appreciated.
--- EDIT --
I've updated my config after more reading and the suggestions of Tim to be:
RewriteCond $0 !^/webroot
RewriteRule ^.*$ /webroot$0 [I]
RewriteCond $0 !-f
RewriteRule ^/webroot/(.*)$ /library/index.php [I,L,QSA]
And it passes to /library/index.php
correctly but it still doesn't check for an existing file (even though it seems to say that it does).
Thu Jul 15 14:47:30 - 3444 - EvalCondition: checking '/webroot/images/buttons/submit.gif' against pattern '!-f'
Thu Jul 15 14:47:30 - 3444 - EvalCondition: cond->SpecialConditionType= 'f'
Thu Jul 15 14:47:30 - 3444 - EvalCondition: Special: it is not a file
I think I'm going to have to contact the author of the Filter.
Upvotes: 2
Views: 3699
Reputation: 5349
I ended up having to swap to using the Helicon Tech ISAPI_Rewrite 3 filter.
The htaccess file I ended up using was:
RewriteEngine On
# Check whether the file exists and if not, check whether the request starts
# with webroot. Prepend webroot if it doesn't.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^webroot
RewriteRule ^.*$ webroot/$0 [NI]
# Check whether the file exists, if not, send the request off to library/index.php
RewriteCond %{DOCUMENT_ROOT}/$0 !-f
RewriteRule ^(webroot/)?(.*)$ library/index.php [I,L,QSA]
Upvotes: 0
Reputation: 19169
Hmm...I hadn't heard about IIRF before, cool stuff. After browsing through the documentation to see what the differences between it and mod_rewrite
are, I have two things you could try.
The first is to swap out %{DOCUMENT_ROOT}
for %{APPL_PHYSICAL_PATH}
in the answer that you found. DOCUMENT_ROOT
is an Apache server variable, and from what I can tell the corresponding IIS variable should be APPL_PHYSICAL_PATH
. I know based on the IIRF documentation that this variable is available, but admittedly I'm not 100% sure whether or not it points to your site root.
The other is to do the following, which again may or may not work based upon whether I understood the documentation correctly, how your index.php
file gets the relevant path information to process the request, and a host of other things. Admittedly I think this is a less than ideal solution (compared to what I had originally thought to do based on how mod_rewrite
does things), but maybe it'll work:
RewriteEngine ON
# This should rewrite to /webroot/whatever then restart the ruleset,
# apparently...On Apache in a per-dir context, this would alter the
# %{REQUEST_FILENAME} for the next run-through. I'm assume it does
# here too, but I might be wrong.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/webroot
RewriteRule ^.*$ /webroot/$0
# The file still doesn't exist, rewrite it back to its original form,
# but move on to the next rule instead of restarting processing. This
# may not even be necessary, but I was hoping this rewrite would have
# side-effects that would make it as if the above rewrite didn't happen.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(/webroot/)?(.*)$ $0 [NI]
# Now, if it still doesn't exist, we'll rewrite it to our
# /library/index.php file, but this may not work based on how you
# get the original request information. Adding the [U] flag will
# create a new header that preserves the "original" URL (I'm not
# sure what it takes the value from if the URL has already been
# rewritten in a previous step), which might be useful.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ /library/index.php
Upvotes: 1