Rewrite Tweaking Help

Topics: Developer Forum, User Forum
Sep 11, 2008 at 8:01 PM
Edited Sep 11, 2008 at 9:48 PM
I have a series of rules, more like a mapping, that takes a dynamic url and translates it to something more friendly.  Works fine and obviously this is just a small sampling of the list of URLs that a generated from the db.

RewriteRule ^/asp/product-overview.html$ /asp/rewrite_test.asp?id=18
RewriteRule ^/asp/product-1-2.html$ /asp/rewrite_test.asp?id=158

That isn't good enough for me :D  I would like to take it a step further and go with some more along the lines of dropping the asp and going with something even stuffing an extra keyword in there.

RewriteRule ^/products/product-overview.html$ /asp/rewrite_test.asp?id=18
RewriteRule ^/subcategory/product-1-2.html$ /asp/rewrite_test.asp?id=158


Now I am not an IIS person I know enough to be dangerous, I have lots of experience with Apache and have never run into an issue with fake subdirectories.  But on IIS this seems to be a big issue, is there something that I need to do in the ISAPI rewrite filter to get around this issue, or is there something easy that I am missing.

Coordinator
Sep 11, 2008 at 8:32 PM

But on IIS this seems to be a big issue, is there soemthing that I need to do in the ISAPI rewrite filter to get around this issue, or is there something easy that I am missing.

what exactly is the issue?  You've said there is a problem with "fake subdirectories" and you want to get around the problem.   But what is the problem, exactly? 

Sep 11, 2008 at 8:46 PM
The issue is that when I try and do the addition of /products (a fake non-existent subdirectory) vs /asp IIS has a fit and throws a 403 error. 
Coordinator
Sep 11, 2008 at 8:57 PM
what version of IIRF are you using?
Can I see the logfile?
Sep 11, 2008 at 9:15 PM
1.2.14 final R2.
I will post the log file in a few minutes.
Sep 11, 2008 at 9:32 PM
sorry for the delay I had to go find it.


--------------------------------------------
Thu Sep 11 16:26:06 2008 - LogFile re-opened.
Thu Sep 11 16:26:06 2008 - AwaitIniChangeAndReinit:  TerminateWatch = FALSE
Thu Sep 11 16:26:06 2008 - FileChangeWatcher(): Await returns (TerminateWatch= FALSE)
Thu Sep 11 16:26:06 2008 - FileChangeWatcher: Await()...
Thu Sep 11 16:26:06 2008 - AwaitIniChangeAndReinit()...
Thu Sep 11 16:26:14 2008 - TerminateFilter
Thu Sep 11 16:26:14 2008 - DllMain PROCESS_DETACH
Thu Sep 11 16:26:14 2008 - AwaitWatcherTermination(): closing dir handle.
Thu Sep 11 16:26:14 2008 - AwaitWatcherTermination(): Waiting 150 ms ...
Thu Sep 11 16:26:14 2008 - AwaitIniChangeAndReinit: Pre-empted...
Thu Sep 11 16:26:14 2008 - FileChangeWatcher(): Await returns (TerminateWatch= TRUE)
Thu Sep 11 16:26:14 2008 - FileChangeWatcher: return()...
Thu Sep 11 16:26:14 2008 - AwaitWatcherTermination(): watcher thread is terminated...

--------------------------------------------
Thu Sep 11 16:26:46 2008 - ReadConfig: setting LogLevel to 5
Thu Sep 11 16:26:46 2008 - ReadConfig: line  11: RewriteRule   1 ^/products/product-overview.html$      /asp/rewrite_test.asp?id=18               (null)
Thu Sep 11 16:26:46 2008 - ReadConfig: not a duplicate rule...
Thu Sep 11 16:26:46 2008 - ReadConfig: line  12: RewriteRule   2 ^/products/product.html$       /asp/rewrite_test.asp?id=158              (null)
Thu Sep 11 16:26:46 2008 - ReadConfig: not a duplicate rule...
Thu Sep 11 16:26:46 2008 - ReadConfig: line  13: RewriteRule   3 ^/products/read-and-react.html$        /asp/rewrite_test.asp?id=2                (null)
Thu Sep 11 16:26:46 2008 - ReadConfig: not a duplicate rule...
Thu Sep 11 16:26:46 2008 - ReadConfig: line  14: RewriteRule   4 ^/products/large-and-in-charge.html$   /asp/rewrite_test.asp?id=1098             (null)
Thu Sep 11 16:26:46 2008 - ReadConfig: not a duplicate rule...
Thu Sep 11 16:26:46 2008 - ReadConfig: Done reading, found 4 rules (0 failed) on 15 lines
Thu Sep 11 16:26:46 2008 - Initialize: Ionic ISAPI Rewriting Filter (IIRF) v1.2.14 final R3
Thu Sep 11 16:26:46 2008 - Initialize: config file 'C:\Windows\System32\inetsrv\IsapiRewrite4.ini'
Thu Sep 11 16:26:46 2008 - Initialize: main threadId= 1468
Thu Sep 11 16:26:46 2008 - Initialize: File watcher thread created.
Thu Sep 11 16:26:46 2008 - FileChangeWatcher(): Enter, threadId=2680...
Thu Sep 11 16:26:46 2008 - GetFilterVersion
Thu Sep 11 16:26:46 2008 - FileChangeWatcher: Await()...
Thu Sep 11 16:26:46 2008 - AwaitIniChangeAndReinit()...
Thu Sep 11 16:26:46 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Thu Sep 11 16:26:46 2008 - OnUrlMap: storing physical path (C:\inetpub\wwwroot\asp\product-overview.html), in ptr (0x01c37818)
Thu Sep 11 16:26:46 2008 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Thu Sep 11 16:26:46 2008 - DoRewrites
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: getting 'url'
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: 128 bytes
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: result ''
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: getting 'url'
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: 40 bytes
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: result '/products/product-overview.html'
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: getting 'QUERY_STRING'
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: 1 bytes
Thu Sep 11 16:26:46 2008 - GetServerVariable_AutoFree: result ''
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: getting 'method'
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: 4 bytes
Thu Sep 11 16:26:46 2008 - GetHeader_AutoFree: result 'GET'
Thu Sep 11 16:26:46 2008 - DoRewrites: New Url: '/products/product-overview.html'
Thu Sep 11 16:26:46 2008 - ApplyRules: depth=0
Thu Sep 11 16:26:46 2008 - ApplyRules: Rule 1 : 1 matches
Thu Sep 11 16:26:46 2008 - ReplaceServerVariables: InputString='/asp/rewrite_test.asp?id=18' out='/asp/rewrite_test.asp?id=18'
Thu Sep 11 16:26:46 2008 - GenerateReplacementString: src='/products/product-overview.html','(null)' ReplacePattern='/asp/rewrite_test.asp?id=18' vec=[[  0, 39] [] ] counts=1,0
Thu Sep 11 16:26:46 2008 - ApplyCaseConversion: before '/asp/rewrite_test.asp?id=18'
Thu Sep 11 16:26:46 2008 - ApplyCaseConversion: after  '/asp/rewrite_test.asp?id=18'
Thu Sep 11 16:26:46 2008 - GenerateReplacementString: result '/asp/rewrite_test.asp?id=18'
Thu Sep 11 16:26:46 2008 - ApplyRules: Result (length 30): /asp/rewrite_test.asp?id=18
Thu Sep 11 16:26:46 2008 - ApplyRules: depth=1
Thu Sep 11 16:26:46 2008 - ApplyRules: Rule 1 : -1 (No match)
Thu Sep 11 16:26:46 2008 - ApplyRules: Rule 2 : -1 (No match)
Thu Sep 11 16:26:46 2008 - ApplyRules: Rule 3 : -1 (No match)
Thu Sep 11 16:26:46 2008 - ApplyRules: Rule 4 : -1 (No match)
Thu Sep 11 16:26:46 2008 - ApplyRules: returning 0
Thu Sep 11 16:26:46 2008 - ApplyRules: returning 1
Thu Sep 11 16:26:46 2008 - DoRewrites: Rewrite Url to: '/asp/rewrite_test.asp?id=18'
Thu Sep 11 16:26:46 2008 - DoRewrites: not recording OriginalUrl (0x010da938)
Thu Sep 11 16:26:46 2008 - DoRewrites: Finished
Thu Sep 11 16:26:46 2008 - HttpFilterProc: SF_NOTIFY_URL_MAP
Thu Sep 11 16:26:46 2008 - OnUrlMap: storing physical path (C:\inetpub\wwwroot\asp\rewrite_test.asp), in ptr (0x01c37818)
Thu Sep 11 16:26:52 2008 - DllMain THREAD_DETACH, threadId= 3452
Thu Sep 11 16:26:52 2008 - DllMain THREAD_DETACH, threadId= 2716
Coordinator
Sep 11, 2008 at 11:29 PM

Iceman, it looks like IIRF is working properly.

I suspect the problem you may be having is this:  the /asp directory is in a different IIS app pool than the /products directory.  Products is probably in DefaultAppPool, and /asp is in its own dedicated pool. 

If my suspicion is right, then you can move /products into the same app pool as /asp, to avoid the 403.

 

Sep 30, 2008 at 7:29 PM
Edited Sep 30, 2008 at 7:35 PM
What happens if there is no real products directory.  :D

RewriteRule ^/asp/product-overview.html$ /asp/rewrite_test.asp?id=18
a little off-topic but if I type in domain.com/asp/rewrite_test.asp?id=18 that the URL would change to the product-overview.html?
Coordinator
Oct 1, 2008 at 10:57 PM
If ther is no products directory, then it is in the default app pool.
Is the /asp in a separate pool?

For your off-topic question,
you have it backwards.

The first part is the pattern.  What you are saying is, if you get a URL that matches that pattern, then rewrite it.
the second part is what you rewrite to. 
This is what will run on the server if the RewriteRule fires.

I suggest you re-check the readme.


Also try out the testdriver.exe tool - you will learn from it.
Try a bunch of rules and a bunch of URLs through it.
Check the example tests for how to use the tool.