Search code examples
debuggingtestingisapi-rewrite

isapi rewrite debugging or test harness


Was wondering if anyone was aware of, or had experience with, debugging a set of isapi rewrite rules?

I have a pretty large set of rules and so it is not easy to manually go through them. So i was wondering if there are any test harnesses available for putting in your rules and passing in a URL, and seeing what rule/s is/are matched and what the resultant URL is?

Or failing that, some kind of advanced logging which might guide me as to where my issues might lie.

Any help would be much appreciated as my brain is about to melt!

Cheers


Solution

  • I've done this with isapi_rewrite's debug logging. It works well, but it won't help with your brain melting. A true debugger would be nice.

    I'll assume you're using isapi_rewrite v3.

    The logging is controlled in the main httpd.conf file. Edit this file with their "Manager" app, default installation at Start -> Programs -> Helicon -> ISAPI_Rewrite 3 -> ISAPI_Rewrite Manager

    Alternatively, you can edit it manually in C:\Program Files\Helicon\ISAPI_Rewrite 3\httpd.conf (or equivalent windows installation directory). I believe it is hidden, so you many need to show hidden files.

    Here are my comments I put into this file, so I remember the settings. Comment the line in and out as needed.

    # Logging
    #  RewriteLog specifies log file.
    #  RewriteLogLevel specifies verbosity. 0 = none, 9 = all.
    #RewriteLogLevel 9
    #  LogLevel is for general logging for config file loading problems, not rewriting. Default is warn.
    #LogLevel debug
    

    The RewriteLogLevel is the setting that turns logging on and off. I generally use 0 or 9. I have tried other settings out of curiosity, but don't know the specifics. Generally I want it all if I'm chasing a problem.

    RewriteLog would specify an alternative log file, but I just leave it unspecified, and it writes to Rewrite.log in C:\Program Files\Helicon\ISAPI_Rewrite 3\ (or equivalent windows installation directory)

    (I have rarely (never?) used LogLevel; I just keep it there, commented-out, to remind myself I don't use it.)

    Uncomment the line by removing the leading #, and saving it. (In their editor, click Apply in the upper left, or ctrl-s; then Apply again in the main dialog. You can leave the main dialog open to quickly comment it out again.)

    The Rewrite.log file will start filling up fast. This is really only practical on a development system, where your requests are the only ones. If you are on production, turn it on, hit the page, and turn it off quickly. The log files have IP addresses which can help locate your rules.

    What you'll see is the initial request passing through all the rules, until it matches. Then you'll see [INTERNAL REDIRECT] which means it's done rewriting the rules (that's a bit of a misnomer that fooled me for a while - it just means it's rewriting from our view, vs the "explicitly forcing redirect" for an actual web redirect).

    Here is a log file example from my answer to this question:
    How to redirect a page in ISAPI_Rewrite

    This redirects /cnvrt to /convert, then rewrites /convert to /convert.aspx

    You can see the first block matching the redirect and doing it. Then the second block is the /convert url matching and getting rewritten to convert.aspx. If there's no match, it just falls through all the rules. You can see this in the third block, where my browser went looking for favicon.ico, which it didn't find.

    These logs are also an eye-opener for how much every request goes through - every image, stylesheet, etc. get put through all the rules. I played around with "shortcut" rules to catch /img, /images, *.css, *.js, and just exit without changing anything. You can see these trying to get matched below.

    A final note: When done, and the logging is turned off, be sure to just open, empty and save Rewrite.log, DO NOT DELETE Rewrite.log There are many posts on the Helicon forums about permission troubles recreating the file. Apparently isapi_rewrite can install it and edit it, but can have troubles recreating it.

    (Deleted IP addresses, date and time, domain and some session id tracking)
    
    (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
    (1) Htaccess process request d:\websitepath\.htaccess
    (3) applying pattern '^(?:/img/|/images/)' to uri '/cnvrt'
    (3) applying pattern '(?:\.css|\.js)$' to uri '/cnvrt'
    (3) applying pattern '(.*)' to uri '/cnvrt'
    (4) RewriteCond: input='www.yourdomain.com' pattern='^(?!www\.|x\.|loc)(.*)$' => not-matched
    (3) applying pattern '^/cnvrt$' to uri '/cnvrt'
    (1) escaping /convert 
    (2) explicitly forcing redirect with http://www.yourdomain.com/convert
    (2) internal redirect with /cnvrt [INTERNAL REDIRECT]
    
    (2) init rewrite engine with requested uri /convert
    (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
    (1) Htaccess process request d:\websitepath\.htaccess
    (3) applying pattern '^(?:/img/|/images/)' to uri '/convert'
    (3) applying pattern '(?:\.css|\.js)$' to uri '/convert'
    (3) applying pattern '(.*)' to uri '/convert'
    (4) RewriteCond: input='www.yourdomain.com' pattern='^(?!www\.|x\.|loc)(.*)$' => not-matched
    (3) applying pattern '^/cnvrt$' to uri '/convert'
    (3) applying pattern '^/convert$' to uri '/convert'
    (1) Rewrite URL to >> /projects/rw/convert.aspx
    (2) rewrite '/convert' -> '/projects/rw/convert.aspx'
    (2) internal redirect with /projects/rw/convert.aspx [INTERNAL REDIRECT]
    
    (2) init rewrite engine with requested uri /favicon.ico
    (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
    (1) Htaccess process request d:\websitepath\.htaccess
    (3) applying pattern '^(?:/img/|/images/)' to uri '/favicon.ico'
    (3) applying pattern '(?:\.css|\.js)$' to uri '/favicon.ico'
    (3) applying pattern '(.*)' to uri '/favicon.ico'
    (4) RewriteCond: input='www.yourdomain.com' pattern='^(?!www\.|x\.|loc)(.*)$' => not-matched
    (3) applying pattern '^/cnvrt$' to uri '/favicon.ico'
    (3) applying pattern '^/convert$' to uri '/favicon.ico'