简体   繁体   中英

IIS URL Rewrite (redirect)

I want to replace "index" with "home" in my URL, eg:

www.mywebsite.com/index should redirect to www.mywebsite.com/home .

www.mywebsite.com/index/contact to www.mywebsite.com/home/contact and so on.

I tried applying this rule

<rule name="Replace index" stopProcessing="true">
    <match url="(.*)(/index)(.*)" />
    <action type="Redirect" url="localhost:6782/home{R:3}" />
</rule>

The rule should pick up (any-string)(/index)(any-other-string) and replace it with localhost:6782/home{any-other-string} but it doesn't do anything.

IIS正则表达式测试模式

Here's the answer to my question:

 <rules>
    <rule name="Redirect to home" stopProcessing="false">
      <match url="^index(.*)" />
      <action type="Redirect" url="home{R:1}" redirectType="Permanent" />
    </rule>
 </rules>

Tip : be sure to clear the cache of the browser when trying out different rules (or use incognito mode)

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