In IIS7, we no longer need to install other components, we can implement the pseudo static of the URL by simple configuration in web.config. The method is as follows:
Add the following code to the configuration node of the Web.config configuration file:
The code is as follows |
Copy Code |
< 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 the rule node is each rewrite rule, the match node is a pseudo static rules, the ignoreCase is ignoring the case, and the action is the URL of the response, that is, whether the real url;appendquerystring is with the argument. When adding more than one rule, note that name names should remain different.
The following directly give the site URL rewrite rules, I believe you will be at a glance:
code is as follows |
copy code |
< 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, in the IIS6 if with the parameter words use $ character, in IIS7 use {R: number} instead of $ character. When it comes to multiple parameters, don't forget to use & Replace & symbol.
If you are IIS6 you can refer to the following method to instantiate the pseudo static
We need to download the Microsoft Official URLRewriter.dll, download some DLL files to our project. Next, you need to do some simple configuration in the web.config, you can implement the redirection of the URL.
First, find the configsections in Webconfig and add the given code at the following location:
The code is as follows |
Copy Code |
</sectionGroup> <section name= "Rewriterconfig" type= "URLRewriter.Config.RewriterConfigSerializerSectionHandler, Urlrewriter"/ > </configSections> |
Next, find httphandlers and add the code in the following location:
The code is as follows |
Copy Code |
<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 to the. html and. aspx suffixes. Finally, we want to add the redirected rule to implement URL redirection.
The code is as follows |
Copy Code |
< /configsections> <rewriterconfig> <rules> <rewriterrule> <lookfor>~/ article/(s+)/(D{8})/(s+). Html</lookfor> <sendto>~/article/default.aspx? Sub=$1&urlname=$3</sendto> < /rewriterrule> </rules> </ Rewriterconfig> |
The top of the
is the rules for redirection, with my own small station as an example. domain/article/article type/publish time/article name. html redirected to domain/article/default.aspx? sub= article type &urlname= article name. I am not very familiar with the positive, ^_^. If you are interested you can learn, and finally do not forget to &urlname & symbols written in & , the