iisurl-rewriting

Add URL rewrite rule on root website for specific URL


Is it possible to apply a URL rewrite based on a matching URL after my website name? So say I have a rule on http://foo:8080 that enables me to go to http://foo:8080/ and that would rewrite to http://too. Is there a way to say that if I access http://foo:8080/bar it will take me to http://too/bar but have the rule on the website foo without any applications underneath it?

This would enable multiple rules on one site to reroute based on where I navigate to in the first place rather than setting up multiple applications for each rewrite rule.

I hope this makes sense, if it doesn't but you think you have an answer please let me know and I'll try to be more clear.

Thanks


Solution

  • Thanks to @MisterSmith for pointing me in the right direction I found the answer to be the below, this also allows for http or https. My config now looks like the below:

     <rewrite>
            <rules>
                <rule name="Rule" stopProcessing="true">
                    <match url="^bar/(.*)" />
                    <action type="Rewrite" url="{C:1}://too:8080/bar/{R:1}" />
                    <conditions>
                        <add input="{CACHE_URL}" pattern="^(https?)://" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    

    The rule is set on the website "foo" and now when I go to http://foo/bar/blahblahblah I get a response from http://too:8080/bar/blahblahblah