IIS7 configuration web.config implement pseudo-static implementation code

Source: Internet
Author: User
Tags to domain

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 &amp; 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 &amp; , the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.