1

I have a folder on my server like this one:

C:\inetpub\wwwroot\blah

In IIS, I also have a "/blah" virtual folder set up, pointing to C:\BLAH

Naturally, when site visitors type in http://www.myserver.com/blah/test.html, IIS looks for C:\BLAH\test.html, not C:\inetpub\wwwroot\blah\test.html. For the most part, this is the behavior I want, because most of the files are in C:\BLAH. However, when the file DOES exist in C:\inetpub\wwwroot\blah, I'd like the server to look for it there first, and then look in C:\BLAH if it doesn't find it. Basically I'd like the files in C:\inetpub\wwwroot\blah to be an "exception" to the virtual directory. Have the server return the files from that folder, if they exist, but if they don't pull them from C:\BLAH instead of returning a 404.

I am running IIS 5.0 on Windows Server 2000.

Is this possible? Thanks.

Joshua Carmody
  • 175
  • 3
  • 9

3 Answers3

1

This is kind of ghetto, but it might be a simple way to solve your problem.

  • Create a second virtual directory that points to c:\blah.
  • In the "blah" virtual directory (which points to C:\inetpub\wwwroot\blah), setup a custom error handler for 404 errors that is an ASP or ASP.Net page in c:\inetpub\wwwroot\blah\
  • In the 404 handler ASP.Net page,
    • pull the requested URL (it should be the only thing in Request.QueryString)
    • chop off everything but the filename requested
    • redirect to "/cblah/FILENAME".

Here is a little snippet of ASP.Net code that could act as the 404 handler:

string qs = Page.Request.QueryString.ToString();
qs = Server.UrlDecode(qs);
int c = qs.LastIndexOf("/");
string filepath = qs.Substring(c+1);
Response.Redirect("/cblah/"+filepath);
MattB
  • 11,124
  • 1
  • 29
  • 36
0

You could probably do this through a custom written ISAPI filter, but I am not aware of any way within IIS or an existing product that would do exactly what you're looking for.

Justin Scott
  • 8,748
  • 1
  • 27
  • 39
0

IIRF is a free URL Rewriter which has a capability to check for the existence of a directory, before rewriting. The rules would look like:

# This rule matches, eg, http://server/blah/test.html
# It does "no rewrite" (-) if the file c:\blah\test.html does NOT exist. 
# The url stub /blah must map to an existing vdir. 
RewriteCond  c:\blah\$1        !-f
RewriteRule  ^/blah/(.*)$      -  [L]

# If the file does exist, rewrite to the alternative vdir. 
RewriteCond  c:\blah\$1           -f
RewriteRule  ^/blah/(.*)$         /override-vdir/$2    [L]

You can also wildcard "blah". To do that you'd need a convention for naming the override vdirs. It would look something like this:

# This rule matches, eg, http://server/blah/test.html
# It does nothing if the file c:\blah\test.html does not exist. 
RewriteCond  c:\$1\$2           !-f
RewriteRule  ^/([^/]+)/(.*)$    -  [L]

RewriteCond  c:\$1\$2            -f
RewriteRule  ^/([^/]+)/(.*)$    /override-$1/$2    [L]

There are also conditions for testing the existence of a directory. Check the IIRF doc for details.

Cheeso
  • 572
  • 3
  • 17