ISAPI Rewrite Filter - need help

Topics: Developer Forum, Project Management Forum, User Forum
Apr 9, 2008 at 1:28 AM
I'm looking for the best example for a regular expression to change requests going to http://mywebsite/map/# to http://mywebsite:81/test.htm?map=# where # will be an integer supplied by an application. Can anyone help me with this expression?



Coordinator
Apr 15, 2008 at 6:01 PM
I suggest you read the doc,
check the examples and tests, and play with the testdriver.exe
Apr 21, 2008 at 8:56 PM
Thanks,
I have read the document extensively but I need a kind of starting point to begin testing. Again to reiterate, I want to send all requests from http://mywebsite/map/# to http://mywebsite:81/test.htm?map=# with map being an integer from 0-1000000

I am using Isapi Rewrite Lite.
thanks in advance and I will be indebted to anyone who can get me started....
Apr 23, 2008 at 6:03 PM

Cheeso wrote:
I suggest you read the doc,
check the examples and tests, and play with the testdriver.exe


I decided not to use Isapi Rewrite Lite and instead switched to IIRF.

I read through your doc, put my rule in the IsapiRewrite4.ini file (see below), placed both the IsapiRewrite4.ini file and the IsapiRewrite4.dll in a subdir, and deployed the dll manually using the IIS Manager. Some logs were written which perhaps you can better interpret. I am confused about the process. I downloaded the binary version not the source assuming that the binary already had the regexpression built in. I only modified the IsapiRewrite4.ini file. Is that enough or do I need to build a new executable? Just a bit of backround. I am running this on a server with 2 websites, one running on port 80 and the other on port 81. Right now all I get is the page not found error. My log is copied below the filter.
thanks in advance


RewriteRule ^my.server.edu/map/(.*) my.server.edu:81/demo/mypage.htm?map=$1 R

Wed Apr 23 12:49:52 2008 - Ionic URL Rewriting ISAPI Filter v1.2.13
Wed Apr 23 12:49:52 2008 - Initialize, main threadId= 1308
Wed Apr 23 12:49:52 2008 - File watcher thread created.
Wed Apr 23 12:49:52 2008 - GetFilterVersion
Wed Apr 23 12:49:52 2008 - FileChangeWatcher(): Enter, threadId=9528...
Wed Apr 23 12:49:52 2008 - FileChangeWatcher: Await()...
Wed Apr 23 12:49:52 2008 - AwaitIniChangeAndReinit()...
Wed Apr 23 12:49:52 2008 - HttpFilterProc SFNOTIFYURL_MAP
Wed Apr 23 12:49:52 2008 - OnUrlMap: storing physical path (G:\wwwroot\PUcampus.html), in ptr (0x000c3740)
Wed Apr 23 12:49:52 2008 - HttpFilterProc SFNOTIFYAUTH_COMPLETE
Wed Apr 23 12:49:52 2008 - DoRewrites
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree: getting 'url'
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree - no joy (likely reason: server var not set yet) (GetLastError()=1413)
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree: 128 bytes
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree: result ''
Wed Apr 23 12:49:52 2008 - GetHeader_AutoFree: 15 bytes
Wed Apr 23 12:49:52 2008 - GetHeader_AutoFree: result '/PUcampus.html'
Wed Apr 23 12:49:52 2008 - GetServerVariableAutoFree: getting 'QUERYSTRING'
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree: 1 bytes
Wed Apr 23 12:49:52 2008 - GetServerVariable_AutoFree: result ''
Wed Apr 23 12:49:52 2008 - GetHeader_AutoFree: 4 bytes
Wed Apr 23 12:49:52 2008 - GetHeader_AutoFree: result 'GET'
Wed Apr 23 12:49:52 2008 - New Url: '/PUcampus.html'
Wed Apr 23 12:49:52 2008 - ApplyRules (depth=0)
Wed Apr 23 12:49:52 2008 - Rule 1 : -1 (No match)
Wed Apr 23 12:49:52 2008 - ApplyRules: returning 0
Wed Apr 23 12:49:52 2008 - No Rewrite
Wed Apr 23 12:50:09 2008 - HttpFilterProc SFNOTIFYURL_MAP
Wed Apr 23 12:50:09 2008 - OnUrlMap: storing physical path (G:\wwwroot\map\7), in ptr (0x000c39f0)
Coordinator
Apr 23, 2008 at 6:11 PM

mjeffe wrote:
Cheeso,
If I am just providing a URL redirect rule, do I need to compile my own dll or can I just edit the .ini file and put my rule in there? I am just slightly confused about the application of using the compiled vs. the uncompiled version. I am guessing that I don't need the source for a hard coded redirect but I could be wrong...


To use IIRF, you just need to install the binary and configure the ini file.
The source is there for the case where you want to change how IIRF works.

Coordinator
Apr 23, 2008 at 6:28 PM
Edited Apr 23, 2008 at 6:47 PM

mjeffe wrote:
I decided not to use Isapi Rewrite Lite and instead switched to IIRF.

I read through your doc, put my rule in the IsapiRewrite4.ini file (see below), placed both the IsapiRewrite4.ini file and the IsapiRewrite4.dll in a subdir, and deployed the dll manually using the IIS Manager. Some logs were written which perhaps you can better interpret. I am confused about the process. I downloaded the binary version not the source assuming that the binary already had the regexpression built in. I only modified the IsapiRewrite4.ini file. Is that enough or do I need to build a new executable? Just a bit of backround. I am running this on a server with 2 websites, one running on port 80 and the other on port 81. Right now all I get is the page not found error. My log is copied below the filter.
thanks in advance


You only need the binary. you configure it by editing the ini file.

From my reading of your log, you passed http://my.server.edu/PUCampus.html as a URL to the server.
And what you got out was no rewrite.
Look at the line in your log that reads:
Wed Apr 23 12:49:52 2008 - Rule 1 : -1 (No match)

This means your REGEX does not match the passed-in URL. And examining the regex, there should be no surprise about that.

Your regex looks for URLs that begin with /map/. And /PUCampus.html does not begin with /map/.

The next thing - thank you for thoroughly reading through the readme file. Writing doc is sometimes a thankless job, and every doc writer appreciates it when someone reads the doc they wrote.

But I would ask that you read the Readme one more time. The example for redirection shows very clearly how you should be specifying the URL pattern to match. In particular, you should not be including the server name in the URL pattern. Also, the redirection target should include the scheme (Http).

This:
RewriteRule ^/map/(.*)  http://my.server.edu:81/demo/mypage.htm?map=$1 [R]

Not this:
RewriteRule ^my.server.edu/map/(.*) my.server.edu:81/demo/mypage.htm?map=$1 [R]


I will update the Readme to include this:

The URL pattern - that is to say the first argument to the RewriteRule directive - matches the URL without the leading Server DNS name. What I mean is, if a user types http://my.server.org/Document.htm into their web browser, the URL you receive at the server is /Document.htm, and your URL pattern should match THAT. Your URL pattern should not attempt to match the leading scheme ("http") nor the server name ("my.server.org").


Apr 23, 2008 at 6:47 PM
thanks. I made the switch and got it to work. I apologize for the initial approach to solving my problem, which was to not look at the documentation. After reading and getting your feedback I have a solution for my customer.

appreciated,
m