Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm attempting to put JetBrains TeamCity (which uses TomCat on port 81) behind IIS 7, so that is proxied to http://myserver:81/. I think I've got it mostly working, except that TeamCity outputs @import in the <style> element. I can't figure out how to define an outbound rule to deal with this.

How do I get URL rewrite to deal with this?

Or, alternatively, can I teach TeamCity about the alternative virtual directory, so that it prefixes everything with /teamcity?

Or, more alternatively, is there a better way to put TeamCity behind IIS 7.5?

share|improve this question

Update: The following doesn't completely work: some of the Javascript is problematic, and the logout redirect is broken.


  1. Host TeamCity in a Tomcat installation that's listening to /teamcity; then there'll be no need for outbound rules. I've got this working for a drupal installation.
  2. Redirect instead (no virtual directory). There are example steps for this elsewhere. This will require some DNS CNAMEs and a wildcard certificate (if using HTTPS for external access).

I'll leave the other instructions here for posterity...

You can configure URL Rewrite to rewrite any part of the text, by setting filterByTags="None".

So I now have the following in C:\Inetpub\wwwroot\web.config:

        <!-- Anything to should be
             rewritten to http://teamcity:81/ -->
        <rule name="TeamCity (/teamcity)">
          <match url="^teamcity/(.*)" />
            <!-- URL Rewrite can't deal with Encoding: gzip; turn that off. -->
            <set name="HTTP_ACCEPT_ENCODING" value="" />
          <action type="Rewrite"
                  url="http://teamcity:81/{R:1}" />

That's the inbound rule; there are three outbound rules:


Login redirects:

        <!-- 302 Redirects (for the login page, e.g.) need to be rewritten. -->
        <rule name="Teamcity (/teamcity) - Redirect" preCondition="IsRedirect">
          <match serverVariable="RESPONSE_LOCATION"
                 pattern="http://[^/]+/(.*)" />
          <action type="Rewrite"
                  value="{R:1}" />

Normal HTML rewriting:

        <!-- Links in HTML need to be rewritten. -->
        <rule name="TeamCity (/teamcity) - HTML" preCondition="IsHTML">
          <!-- I've ellided the other tag types here; you might want them. -->
          <match filterByTags="A, ..."
                 pattern="^(.*)" />
          <action type="Rewrite"
                  value="{R:1}" />

@import of CSS files:

        <!-- TeamCity uses @import for styles; fix that. -->
        <rule name="TeamCity (/teamcity) - Style" preCondition="IsHTML">
          <match filterByTags="None" pattern="@import &quot;/" />
          <action type="Rewrite" value="@import &quot;/teamcity/" />

And some pre-conditions:

          <preCondition name="IsRedirect">
            <add input="{RESPONSE_STATUS}" pattern="302" />
          <preCondition name="IsHTML">
            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />


It appears to work, but I'll come back and update this answer if I find anything else.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.