Iis 7 configure web.config to implement pseudo-static implementation code

  
                  

In IIS7 we no longer need to install other components, and the pseudo-static of the URL can be achieved by simple configuration in web.config. Here's how:

Add the following code to the configuration node of the web.config configuration file:
Code is as follows

<system.webServer> <rewrite> <rules> <rule name ="rulename"> <match url="newurl" ignoreCase="false" /> <action type="Rewrite" url="oriurl" appendQueryString="false" /> < ;/rule> </rules> </rewrite> </system.webServer>

where rule node is the rule for each rewrite, match node is pseudo-static; ignoreCase is ignored Case; action is the URL of the response, the real URL; appendQueryString is the parameter. When adding multiple rules, be aware that the name name should remain different.

The following directly gives the URL rewriting rules of this site, I believe everyone will know at a glance:
The code is as follows

<rewrite> <rules> <rule name="rule1"> <match url="articles/(S+).html" ignoreCase="true" /> <action type="Rewrite" url="articles/Default.aspx?SubClass={R:1} " appendQueryString="true" /> </rule> </rules> </rewrite>

Visible, if you use the $ character with IIS6, use {R in IIS7 : Number} instead of $ character. When it comes to multiple parameters, don't forget to replace the & symbol with &amp;.

If you are iis6, you can refer to the following method to instantiate pseudo-static

We need to download the official URLRewriter.dll provided by Microsoft. After downloading, we will refer to some dll files in our project. Next, you need to do some simple configuration in web.config to implement url redirection.

First, find configSections in webconfig and add the given code in the following location:
The code is as follows

</sectionGroup> <section name="RewriterConfig" type="URLRewriter .Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> </configSections>

Next, find httpHandlers and add the given code in the following location:
The code is as follows <httpHandlers> <add verb= "*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> <add verb="*" path="*.html" type="URLRewriter. RewriterFactoryHandler, URLRewriter" />

The code added above will redirect the url path of the .html and .aspx suffixes. Finally, we want to add a redirected rule to implement url redirection.
Code is as follows

</configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/article/(S+)/(d{8})/(S+).html< /LookFor> <SendTo>~/article/default.aspx?Sub=$1&UrlName=$3</SendTo> </RewriterRule> </Rules> </RewriterConfig>

This is the rule of redirection. The above is an example of my own small station. Redirect domain/article/article type/release time/article name.html to domain/article/default.aspx?Sub=article type&UrlName=article name. I am not very familiar with the regularity, ^_^. If you are interested, you can learn, and finally don't forget to write the & symbol in &UrlName to &amp; ,

Copyright © Windows knowledge All Rights Reserved