Santry Technology Solutions, Content Management, DotNetNuke, SharePoint Consulting
Register | Login
Wednesday, January 07, 2009

Sections
  
About Us
  
Partners
Downloads
  
 WWWCoder.com Resource Directory

ISAPI Rewrite
1/16/2005 6:00:08 PM

Have you ever wanted to manage multiple domain names under a single account in IIS (Internet Information Services)? A common way to do this is to handle it from code. There are some disadvantages when handling this directly from code. Static pages aren't redirected, non-developers will need to purchase or dust off their programming books, and evidence remains that a redirection was done.

Along came ISAPI Rewrite www.isapirewrite.com to solve this issue. Running at the ISAPI level in IIS, this is done before any page or code is accessed so it works equally well on static and dynamic content. It overcomes all the objections mentioned above.

With common redirection code, the user would see something like this:
http://www.domain1.com
http://www.domain2.com/domain2
http://www.domain3.com/domain3

With the ISAPI Rewrite component, the user will see this:
http://www.domain1.com
http://www.domain2.com
http://www.domain3.com

Even though behind the scenes the sites can be in completely different sub-folders, the person visiting the website won't have any concept of this. They will simply see the clean domain names.

ISAPI Rewrite will rewrite (kind of like a redirect) the user to a sub-folder even though the web browser doesn't realize this.

This is done very fast and efficiently and managed by a file called httpd.ini which should be placed in the root of the site. It controls which domain names are handled by which sub-folder by utilizing different regular expression rules.

Some tips to remember when creating the rules.

# is used to comment out a line

The following characters must be preceded by a "" to be recognized as a literal character ( meaning a character that represents itself)

".", "*", "?", "+", "(", ")", "{", "}", "[", "]", "^" and "$".
This becomes important when typing (www.domain.com) it would have to look like (www.domain.com)

Parentheses are used to group items together to be marked as what is to be matched, such as "(apple)*" would match all of the string "appleappleapple".

You can see more helpful expression tips here, http://www.isapirewrite.com/docs/examples

Some examples of the rules you will see in the httpd.ini file look like this:

#manual redirect of one domain
RewriteCond Host: (www.)?domain1.com
RewriteRule (.*) /domain1$2

#redirecting to another URL
RewriteCond Host: (www.)?domain1.com
RewriteRule (.+) http://www.domain2.com$1 [R]

#Rewrite just one domain but keep the old link working
RewriteCond Host: (www.)?domain1.com
RewriteRule (?!/domain1)(.*) /domain1$2 [I]

Many tricks come with a catch, and this is no exception. One disadvantage that I have come across is that the response.write from ASP or ASP.NET does not work well in conjunction with this component. Absolute paths are required since relative paths are done after ISAPI Rewrite handles the request and aren't redirected as would be expected. The workaround is to use absolute paths with the full domain name in the redirect. If Server.Transfer is to be used, it should be tested as well. It runs into similar issues.

Additionally, when using ASP or ASP.NET, the new virtual root folder should be marked as an application so that the new virtual root's folder is used for global.asa(x), web.config and /bin.

About the Author

Pam Dean is Web Support Specialist with ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 11/11/2007 7:52:46 PM by Anonymous
Comments: Hello! Good Site! Thanks you! qxmovhoqxs
Left on 5/15/2006 10:57:58 AM by Anonymous
Comments: Pam's last comment about marking the new virtual root's folder as an application is wrong I believe. So far as the ISAPI Rewrite documentation is concerned, you can't rewrite the URL accross an application boundary so it wouldn't work. Unless you do a redirect rather than a rewrite, which would then show the new url in the browser and defeat the objective.
Left on 7/6/2005 11:02:38 PM by Anonymous
Comments: ISAPI redirect continues to send me to the MSN site instead of the home page that I have specified.  I have tried multiple times to change the home page settings, but ISAPI rewrite ignores the changes.  It is highly irritating.
Left on 2/14/2005 4:50:06 AM by Anonymous
Comments: One disadvantage that I have come across is that the response.write from ASP or ASP.NET does not work well in conjunction with this component
>> did you mean response.redirect here?
No ratings available.
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970