简体   繁体   中英

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:

  • www.example.com rewrite to server A:
  • siteB.example.com rewrite to server B:
  • siteC.example.com rewrite to server C:

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:

  • www.example.com/siteD rewrite to server D:

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

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:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM