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
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
.
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.
Allright thanks for the answer, I read the docs provided by Lex Li and even his articles, I understood the principle and we found a solution here at work, an ugly one. I changed the meta tag in the html file but my boss wants to keeps the URL maps.swcs.be in the browser not the redirected one. I found out, it's a 301 redirect. So to say it simply, maps.swcs.be should redirect to my page ServerName/Example/index.html
You can use rewrite to keep maps.swcs.be in browser like this<rule name="redirection"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="maps.swcs.be" /> </conditions> <action type="Rewrite" url="ServerName/Example/index.html" /> </rule>
If your solution can work, please post it as answer so that can help others with similar problems.
Sorry Zhang, it doesn't wwork, I tried your rule and the html tag together, it redirect me correctly but it doesn't keep the URL like I want... I swear I'm cursed ^^
It's ok. The new rule is rewrite not redirect. What's the url you want to keep? Could you describe the effect you want to achieve in detail, because you keep mentioning the html tag. You'd better clear cookie and cache before enter the url in browser. If it still cannot keep url, I suggest you enable fail request tracing to check the process.