简体   繁体   中英

write a redirect rule in web.config in asp.net application

I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:

device.domain.net/collection/hgkhghj should return to device.domain.net/collection

I can have anything at the place of hgkhghj . If i am writing device.domain.net/collection then it should return device.domain.net/collection

 <rule name="Help Redirect" stopProcessing="true">            
            <match url="(.*)/collection(.*)" ignoreCase="true" />
            <action type="Redirect" url="http:/device.domain.net" appendQueryString="false" redirectType="Permanent" />
          </rule>

but currently it is returning to device.domain.net.

I want to make one more Rule in which if i enter device.domain.net/gcfhgg then it should return to device.domain.net.

<rule name="Help Redirect" stopProcessing="true">            
        <match url="(.*)" ignoreCase="true" />
        <action type="Redirect" url="http://device.domain.net" appendQueryString="false" redirectType="Permanent" />
      </rule>

But it is not working.

For your first rule you could use the following (assuming it is on the same domain):

<rule name="Help Redirect" patternSyntax="ECMAScript" stopProcessing="true">
  <match url="^collection/(.*)" />
  <action type="Redirect" url="collection" appendQueryString="false" redirectType="Permanent" />
</rule>

If this is on another domain you will need ARR installed as well. Your second rule is more complicated as it looks as if you are attempting to perform a redirect only if you hit a 404 page. This is something I have never done using rewrite rules. Is there a reason for doing this as opposed to showing a custom 404 page?

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