May 13, 2010

Setting up and configuring Mercurial in a Windows/IIS/Active Directory environment - Part 2/4

Part 2: Masking hgwebdir.cgi in our URL

This blog post is part of a four part series for getting Mercurial up and running in a Windows environment and hosting it on IIS 5.1 (i.e. Windows Server 2003).

  1. Part 1 Getting Mercurial set up in IIS and hosting a repository at
  2. Part 2 Getting IIS to hide hgwebdir.cgi in the URL for your Mercurial repositories.
  3. Part 3 Locking down security using Active Directory so that only authorized users can view, clone, pull and/or push to a repository.
  4. Part 4 Customizing the theme/skin of the web interface of your Mercurial repositories.

In part 1 we got Mercurial up and running in IIS and created a repository that we can pull from and push to.

The next step is to get rid of that god awful hgwebdir.cgi in the URL so we can have a nice URL - perhaps like: instead of

  1. Download and install Helicon's ISAPI Rewrite 3 - Note: if you need ISAPI Rewrite to work only on specific sites on your server, you need the $99 version. If it can be applied to all sites hosted on your server you can get the free lite version.
  2. Open the ISAPI Rewrite manager.
  3. Click the website (if you purchased the $99 version) or the IIS Web Sites node if you got ISAPI Rewrite Lite.
  4. On the right side of the window you will see the config file listed as <InstallDir>\Helicon\ISAPI_Rewrite3\httpd.conf. Click the edit button.
  5. Add the following rule:
    • RewriteRule /[<ReposFolder>/](.*) /hgwebdir.cgi/$1 [I,O]
    Replacing <ReposFolder> with a nice display name to show instead of hgwebdir.cgi - on my system is use Repos
  6. Set the baseurl property in your hgweb.config file to the nice display name you set in the previous step.
    baseurl = /Repos/

The reason we replace hgwebdir.cgi with a nice name instead of just hiding it altogether is that we only want the rule to fire when we're calling repositories, not when we're calling other resources on the server. If for instance we were to use:

RewriteRule /(.*) /hgwebdir.cgi/$1 [I,O]

This would fire for every page we requested regardless of whether or not we were looking for a repository or not. The idea is that you only want the rule executed in a minimal set of circumstances.

Now we can access our repository using and the cgi will be invoked correctly because the rule rewrote the address from to

Next - Configuring repository security access using Active Directory.

No comments:

Post a Comment