Warm tip: This article is reproduced from serverfault.com, please click

Problem to rewrite an old URL to a new one in IIS manager and web.config file

发布于 2020-09-24 09:03:25

I'm here in last resort. So here is my problem, At work my boss asked me to rewrite an URL to be more user friendly.

The old pattern is this one: https://{hostServer}/SiteName/index.html

The new one should be this one: https://maps.swcs.be

But i looked in the doc of IIS, looked in here for some more informations etc...

I learned, it's done in the web.config file at the root of the repo "wwwroot" So I wrote my rule in there

here it is

<system.webServer>      
  <rule name="redirection d'url">
    <match url=".*"/>
      <conditions>
        <add input="{https://maps.swcs.be}" type="Pattern" pattern="Ëxpertises[0-9]\index\.html">
      </conditions>
    <action type="Rewrite" url="https://maps.swcs.be" />
  </rule>
</system.webServer>

I tried the <action type="Redirect" ...> too and other stuff but it's the only one that returned something... the IISstart.htm file

I'm pretty new to URL redirection, if one of you could enligthen me that would be awesome

Thanks in advance

Questioner
Louis
Viewed
0
Bruce Zhang 2020-09-25 15:35:46

First of all, I highly recommend that you read the documentation provided by lex li in detail, which can help you fully understand how to use url rewrite.

Secondly, I want to know your initial url and rewritten url, you don’t have to show the correct url, just an example. Such as initial url is http://example.com/aaa/bbb/ccc/index and rewritten url is http://example.com/index

So I assume your initial url is https://{hostServer}/SiteName/index.html and rewritten url is https://maps.swcs.be. enter image description here enter image description here

This rule will match the uri, if the uri is /SiteName/index.html, it will redirect to https://maps.swcs.be. You can also change antion type to rewrite. If you choose rewirte, nothing will happen when you check url in browser. But redirect will make the url change to new one in browser.