For those of you using ISAPI_Rewrite Version 2.0, we have what we call our Default rules that we start with. We will then modify these to reflect the environment we are working in. But, for the most part, these are the things you'll need to account for when doing a rewrite on IIS.
Please keep in mind that as soon as you install an ISAPI filter like this, the default settings from the server no longer function properly (e.g. appending trailing forward slashes when at a root level, etc.). You need to add rules for each of those so you can put them back to normal.
[ISAPI_Rewrite] # Webresource file for ASP.NET RewriteRule /(webresource.axd.*) /$1 [I,L] # Block external access to the httpd.ini and httpd.parse.errors files RewriteRule /httpd(?:\.ini¦\.parse\.errors) / [F,I,O] # Block external access to the Helper ISAPI Extension RewriteRule .*\.isrwhlp / [F,I,O] # Exclude anything that starts with _ for FrontPage extensions, if enabled. # e.g. _derived, _private _vti_cnf RewriteRule (.*/_.*) $1 [I,L] # Place any exceptions here. # Example here showing to execute any images, css, js, as is. RewriteRule /(js¦nav¦images)/(.*) /$1/$2 [I,L] RewriteRule (.*)(\.css¦\.js) $1$2 [I,L] # Set different robots.txt for different protocol. # You need to create a robots.https.txt (update this to point to the correct script) RewriteCond %HTTPS on RewriteRule /robots.txt /robots.https.txt [I,O,L] # Move anything from non- www.example.com -> www.example.com # e.g. example.com -> www.example.com RewriteCond %HTTPS off RewriteCond Host: (?!^www.example.com)(.+) RewriteRule /(.*) http\://www.example.com/$2 [I,RP] # Same as above but for SSL. RewriteCond %HTTPS on RewriteCond Host: (?!^www.example.com)(.+) RewriteRule /(.*) https\://www.example.com/$2 [I,RP] # Add trailing slash for folders. RewriteRule ([^.?]+[^.?/]) http://$1$2/ [I,RP] # Convert all upper case to lower case. # If you are using http post, you must make sure everything in the URI are lower case. # Otherwise, the redirect will lose the form values. RewriteCond URL ([^?]+[[:upper:]][^?]*).* RewriteHeader X-LowerCase-URI: .* $1 [CL] RewriteCond %HTTPS on RewriteCond X-LowerCase-URI: (.+) RewriteRule [^?]+(.*) https\://www.example.com$1$2 [I,RP] RewriteCond %HTTPS off RewriteCond X-LowerCase-URI: (.+) RewriteRule [^?]+(.*) http\://www.example.com$1$2 [I,RP] # If you have any folders/files that need to be SSL enabled, list them here. # Redirect all the following folders to SSL if it's not SSL currently. RewriteCond %HTTPS off RewriteRule /(client¦admin¦contact)/(.*) https://www.example.com/$1/$2 [I,RP] # This line will execute the code since it passed all the above checks and it's still SSL. # The matching expression should be the same as last line. RewriteCond %HTTPS on RewriteRule /(client¦admin¦contact)/(.*) /$1/$2 [I,L] # This will force ANY https:// to http: if they are not in the last rule above. RewriteCond %HTTPS on RewriteRule (.*) http://www.example.com$1 [I,RP] # This will 301 all index. requests to the root level for that directory. RewriteRule (.*/)index\.asp $1 [I,RP,L] # This will 301 old URI to new URI. RewriteRule /sub/oldfile.htm http://www.example.com/sub/newfile.asp [I,O,RP,L]
Again, these are "our" default rules. Yours may vary depending on your level of regex expertise and the type of dynamic environment you are developing.
ISAPI Rewrite is a powerful URL manipulation engine based on regular expressions. It acts mostly like Apache's mod_Rewrite, but it is designed specifically for Microsoft Internet Information Server (IIS).
ISAPI Rewrite is an ISAPI filter written in pure C/C++ so it is extremely fast. ISAPI Rewrite gives you the freedom to go beyond standard URL schemes and develop your own scheme.
ISAPI Definition: Internet Server Application Program Interface