Max
Max

Reputation: 171

IIS Rewrite rule for a subfolder path

i am hosting a couple of websites on different servers and i am using IIS 10 + url rewrite on the frontend server as a reverse proxy only.

the redirection is as follows :

This scheme allows me to only have one certificate to manage for all my subdomain websites

This is working fine on subdomains with conditions matching rules.

Now i want to do a rewrite rule from a sub directory to map the entire site D to that subdirectory.

example:

the site redirects the first page but the aspect look weird and links are not functioning.

is it the right way to handle that with conditions {C:2} or should the pattern be applied to the match url ?

here is my web.config :

<rule name="www.example.com_site_d" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                        <add input="{HTTP_HOST}" pattern="^www.example.com$" />
                        <add input="{REQUEST_URI}" pattern="^(/siteD/)(.*)$" />
                    </conditions>
<action type="Rewrite" url="http://myinternalsited:80/{C:2}" logRewrittenUrl="true" />

Thanks

Upvotes: 0

Views: 3590

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28267

As far as I know, the REQUEST_URI means the entire URL path with querystring.

If the REQUEST_URI is /siteD/test?q=IIS+url+rewrite, the result of C:2 is:test?q=IIS+url+rewrite.

Result:

enter image description here

If the REQUEST_URI is /siteD?q=IIS+url+rewrite,the condition will not be matched.

Upvotes: 0

Related Questions