Setting up a friendly URL for Confluence using IIS7 Url Rewriting

Posted: Mon 23 Aug, 2010

We recently installed Confluence (from Atlassian) onto one of our servers.  Confluence runs its own web server, and since we already have IIS running on port 80 (as standard on a Windows Server OS), we configured Confluence to run on a diferrent port.  One thing we don't like however, and which our non-technical staff especially hate, is having to remember port numbers (in this case port 8081) when typing a browser address. The IIS 7 URL Rewrite module is a solution which allows us to transparently forward requests on the standard port 80 to another port.

For example if your Confluence installation runs on http://localhost:8081, you can set up an address like http://confluence.mydomain.com to access it using URL Rewriting.

  1. Install the module (link above).
  2. Create a DNS entry for your site, e.g. confluence.mydomain.com -> web server IP address.
  3. Create a folder in wwwroot for your website
  4. Set up a web site in IIS7 manager as you normally would, pointing to that folder.  Set up binding for confluence.mydomain.com
  5. You can configure the URL rewriting settings via the GUI, or you can edit them via a web.config, which is placed in the root folder of the site.  The web.config I use is given below.
  6. When you create a document in confluence that has spaces in the name, it will substitute +'s for the spaces in the URL.  By default IIS won't process this properly as it is viewed as a security risk.  Instead you will see a 404 error if you view the site remotely, or a more informative 404.11 if you try locally. Nonetheless we need to disable this behaviour for our Confluence redirect to get it working properly.  You can open up the Request Filtering section, click on the 'Edit Feature Settings' link, then tick 'Allow double escaping', or if you use the web.config below it is already set.

At this point you should be able to check and see if it is all working by browsing to your site, e.g. http://confluence.mydomain.com

If you are having trouble setting up your URL Rewriting, it is useful to know that there is a way to view a comprehensive trace of the process, follow this link for details.

Sample extract of a working web.config:



<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Reverse Proxy to confluence" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*" />
                    <action type="Rewrite" url="http://localhost:8081/{R:1}" logRewrittenUrl="true" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="*8081*" negate="true" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
        <security>
            <requestFiltering allowDoubleEscaping="true">
                <requestLimits maxUrl="4096" maxQueryString="2048" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

Blog comments powered by Disqus