Apache LocationMatch directive

Topics: User Forum
Oct 8, 2008 at 12:16 PM
Could I please get some help... I am used to working in Apache but have  a client that insists on IIS so I am trying to replicate my process in Apache. Is Ionic's Isapi Rewrite Filter able to perform something like  the Apache LocationMatch directive? What I need is to do a Location Match and then hand off processing of that URL to lasso8-handler. Then, with Lasso I parse the URL and pull up all the necessary pages through various schemes.

The following Apache configuration of a virtual host will pass on all requests that do not contain a period (with or without an ending slash) to be processed by Lasso (if you are not aware of that, its similar in many ways to PHP).  Here is what I have in Apache (something like):

<Virtualhost *:80>
    Servername vr_tools.local
    DocumentRoot "/Users/path/to/the/directory/web/"
    <LocationMatch "^[^\.]{1,245}$">
         SetHandler lasso8-handler
    </LocationMatch>
    <LocationMatch "^[^\.]{246,}$">
         Deny from all
    </LocationMatch>
    <LocationMatch "^[^\.]{1,245}/$">
         SetHandler lasso8-handler
    </LocationMatch>
    <LocationMatch "^[^\.]{246,}/$">
         Deny from all
    </LocationMatch>
</Virtualhost>

I do not want any actual re-writing of the URL. But i could use the [U] modifier to preserve that if need be.
Coordinator
Oct 8, 2008 at 5:12 PM

Not sure - you might be able to rewrite and send the request to Lasso.

But I don't know how Lasso works.

LocationMatch just checks the incoming URL and then applies the directives inside the LocationMatch scope only to URLs that match.

You can do something similar with a rewrite engine, obviously.  The key thing is, I don't know how that lasso handler works, or how requests get to it.

You could definitely do the "deny" thing with IIRF, based on the incoming URL. Use the same regex you have with apache and apply [F] forbidden flag.

Oct 8, 2008 at 8:30 PM
The thing is, I do not actually want the URL to be rewritten... I just want the request to be handled by Lasso. I can use a wildcard in IIS to process all files by some application, however then IIS will send all resources to that (css, jpg, pdf, etc) which is not what I want. I only want URLs that have no  extension to be sent to lasso
Oct 9, 2008 at 7:15 AM
Is it possible to rewrite the URL to pass requests on to a different host?

Could someone look at the syntax of my IsapiRewrite4.ini file:

RewriteCond %{HTTP_HOST} (abc\.mysite\.com).*$ [I]
RewriteCond %{HTTP_URL} ^[^\.]+$
RewriteRule ^.*$  http://lasso.mysite.com/$1 [L]

What I am trying to do is to look at the host to make sure its on the original host, then to check if there are any periods in the URL, if none, then rewrite to take that url to the secondary host. Then, in IIS I simply setup the application mapping so there is a wildcard that sends every request to Lasso.
Oct 10, 2008 at 2:11 AM
I continue to struggle with this, 2 days on now... its still not working.  What I am trying is to create an additional web site in Windows IIS, then to route all requests to the first website for unknown file resources  over to this additional site. I am using Ionic's Isapi Rewrite Filter (http://www.codeplex.com/IIRF/) to intercept all server requests and process rewrites as follows:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  http://lasso.mysite.com/$1 [L]

I am not certain if that is correct, but my intention is to test if there are no files and no directories in the current URL, and if not, route that request over to a secondary host I have setup in IIS using a different website. That additional web site is setup with a wildcard in application mapping to direct all requests to lasso for processing. My questions on this though are:

1) Does -f and -d really check if the file resource exists prior to applying the rewrite rule, is that a valid approach?

2) Is my rewrite rule correct?

3) Does IIS allow for URLs that do not appear to be correct, that is, have no extension, or will it always fail prior to passing on the request to lasso?

Michael
Coordinator
Oct 14, 2008 at 5:27 AM
Yes, the -f and -d things work as documented.

It looks mostly correct, but to redirect to a different website, you need the [R] flag on the rewrite rule. 
I cannot say if it will suit your purposes; you will have to test it. 
 
I don't know what you mean by #3.    IIS doesn't make judgment calls on the beauty of URLs.  URLs do not need to have "an extension".

http://foo/bar/bam is a valid URL, whether your server is IIS, Apache, or something else. 

Oct 15, 2008 at 10:09 AM
Please help.. I cannot get any redirection at all. How do I go about testing and debugging?

This is my current .ini file.

RewriteLog c:\temp\ispirwrite.out 5
RewriteCond %{HTTP_URL} !^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  http://lasso.atrinternational.com/$1 [R,L]

I am trying to log everything but the log so far just says "TerminateFilter"

Michael
Coordinator
Oct 16, 2008 at 6:32 AM
instead of
RewriteLog c:\temp\ispirwrite.out 5

try
RewriteLog c:\temp\iirf.out
RewriteLogLevel 5