About ruby on rails, hackintosh, iphone3g and etc.

Friday, May 8, 2009

Using ISAPI Rewrite on Rails App with IIS and Mongrel as Windows Service

In setting up a multiple production environment in a single server, IIS alone cannot do the redirection of url nicely. When a RAILS app runs in IIS, it requires port number and to redirect domain name to the particular port number, ISAPI Rewrite can help. Below are some sample of how to redirect a hostname to the port required.

RewriteCond %{HTTP:Host} ^(?:www\.)?domain name\.biz$
RewriteRule (.*) http://www.domain name.biz:3000$1 [R=301,L]

RewriteCond %{HTTP:Host} ^(?:www\.)?another domain name\.com$
RewriteRule (.*) http://www.another domain name.com:3001$1 [R=301,L]

Updated: 27th May 2009
Possible to do URL masking by using rewrite proxy

RewriteCond %{HTTP:Host} ^(?:www\.)?another domain name\.com$
RewriteProxy (.*) http://localhost:4002$1

Note: it will map to localhost:4002 and transparent to user as the url shown is www.anotherdomainname.com. You can point multiple domain name to a single web app.

To get this done:
1. Install ISAPI Rewrite.
2. Copy and replace domain name to your own domain name in ISAPI rewrite.
3. If you have more than one domain pointing to the same server, just add below the first domain.

No comments: