IIS Rewrite rule doesn't work for subfolders

Karim Darbeida 0 Reputation points
2024-11-14T15:01:53.98+00:00

Hello,

I need to enable a rewrite URL in IIS for my old TFS server ( Team Foundation Server).

The default website on 80 port, and tfs root website on 8080 work well, it rewrite the url well to my temporary website correctly, but it can't catch the tfs subfolder , I tested all the possibilities ....(only with match url, with conditions ... no way), I suspect tfs web.config right now ..

Here is my url rewrite configuration :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Forward root">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://sptfs2:81" />
                </rule>
                <rule name="forward" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
                    <match url="^/tfs/(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://sptfs2:81" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    <location path="tfs">
    </location>
</configuration>

can you tell me what I missed please ?

Thank you

Internet Information Services
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 10,761 Reputation points Microsoft Vendor
    2024-11-15T08:15:54.3533333+00:00

    Hi @Karim Darbeida,

    but it can't catch the tfs subfolder , I tested all the possibilities ....(only with match url, with conditions ... no way)

    Because the first rule has already intercepted all requests(match the url)and rewritten them to "http://sptfs2:81", so it will never match the second rule.

    And I'm not sure why you're rewriting the actions of both rules to the same path, if that's what you want then you only need the first rule. But if you just want it to match subfolder paths, you can change the order of the two configured rules and add the attribute stopProcessing="true" to the forward rule.

    If I misunderstood your requirements, please describe your site structure and rewrite/redirection needs in detail.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.