简体   繁体   中英

web.config Rewrite Base Folder to Different Folder

I am using the .net web.config rewrite module. I need to make a rule to redirect any traffice from https://dr.domain.seuss/Cat/ ...... to https://dr.domain.seuss/Hat/ ......

I have this but this is broken and I'm not sure how to proceed.

    <rule name="Folder Redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}{REQUEST_URI}" pattern="(.*)/Cat/(.*)" />
        </conditions>
        <action type="Redirect" appendQueryString="false" url="https://{HTTP_HOST}/Hat/{R:1}" redirectType="Permanent" />
    </rule>

I was able to finally find the solution after trying a ton of different approaches. This is what worked for me:

    <rule name="Force Redirect To Different Folder Name" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_URI}" pattern="^Cat" ignoreCase="false" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/Hat/" redirectType="Permanent" />
    </rule>

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