ISAPI ReWrite has been driving me up the wall for the last day or two. I have Version 3 (fully registered) installed on a web server, which has half a dozen individual web sites up and running. I wanted to implement some rewrite rules for one of the web sites, so I used the ISAPI ReWrite Manager interface to edit the .htaccess file in the root of that specific web site and add a rule along the lines of:
RewriteRule /register/([^/]+)/ /register/register.asp\?eventId=$1 [I,L]
I already have this web site running on my development server, and I know this rule works.
The rules didn't work. I moved them up to the top level of the Manager, which edits the httpd.conf file in the installation directory for ISAPI ReWrite. And the rules worked.
I turned on logging by adding this to the httpd.conf file:
The logging clearly showed the .htaccess file being accessed and the rules in that file being run through:
Htaccess process request d:\inetpub\wwwroot\mydomain.com\.htaccess
applying pattern '/register/([^/]+)/' to uri 'register/My-Event-Name/'
But no dice in the browser, just file not found errors. So the rule is being processed, but the resulting URL clearly is not right.
I read through the troubleshooting information on the Helicon web site. Which is when this phrase caught my eye:
Also remember that rewriting base inside .htaccess files by default is different from httpd.conf. ISAPI_Rewrite automatically strips the local directory prefix from the path when in .htaccess or <Directory> section and applies rules only to the remainder. So if your rules start with a '/' character, this should be removed in .htaccess file in the root folder of web site.
This is the first time I've used the registered version of ISAPI ReWrite, in the past I've only used the Lite version, mostly because I didn't need to bring rules down to the level of the individual web site (on this project I will need to because multiple sites will need the same URL/folder combinations).
So the idea that there is a subtle but key difference in the way you construct the rewrite rules between .htaccess at the individual site level, and the top level httpd.conf file has never come across my radar before.
I amended the rule to:
RewriteRule register/([^/]+)/ /register/register.asp\?eventId=$1 [I,L]
Notice there is no forward slash in front of the register/ name. And the redirect worked completely fine.