Urlrewriter Configuring IIS to support pseudo-static

Source: Internet
Author: User

The use of Urlrewriter encountered some problems, in the garden in the Bo asked to find the answer to Astar , to prevent later can not find, recorded.

Urlrewriter.net Official Address: http://urlrewriter.net/

English Help Center: http://www.urlrewriter.cn/
Description: urlrewriter.net provides a URL on the ASP. NET Level Rewriter

Configuration:
<!--set Address rewriting components--
<configSections>
<section name= "Rewriter" type= "Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.urlrewriter "/>
</configSections>
<!--address rewriting rules--
<rewriter>
<rewrite url= "^/user/(\d+) $" to= "~/user.aspx?id=$1" processing= "Stop"/>
<rewrite url= "^/user/(\w+) $" to= "~/user.aspx?name=$1" processing= "Stop"/>
</rewriter>
Address rewrite rules can be linked to external XML files: <rewriter file= "~/app_data/rewrite.xml"/>
<?xml version= "1.0" encoding= "Utf-8"?>
<rewriteRules>
<rewrite url= "^~/article/([^\.] +) \.html$ "to=" ~/article/display.aspx?n=$1 "/>
</rewriteRules>
<!--httpmodules-->
<system.web>
<add name= "Urlrewriter" type= "Intelligencia.urlrewriter.rewriterhttpmodule,intelligencia.urlrewriter"/>
</system.web>
Precautions:
Processing= "Stop": urlrewriter.net when a matching rewrite rule is found, it will not stop there, but will continue to look for the remaining matches and, ultimately, the last rewrite rule that will match the current request. If we need urlrewriter.net to take effect after a match is found, we need to set the processing property to stop. For example, in the above configuration, if the "/user/" followed by a number, the user ID will be used to find, otherwise it is assumed that the current supply is the user name.
The regular in the URL must be sealed with a small scratch, and the incoming URL conforms to the setting rules in the URL such as: Url= "^~/article/([^\.] +) \.html$ "Incoming must be fda.html,aaa.aspx is not possible, after modifying the regular style to reload the solution.
Introductory article:
1. Simply implement/remove question marks
<rewrite url= "^~/article/([^\.] +) \.html$ "to=" ~/article/display.aspx?n=$1 "/>
Description: The URL rule must be "in addition to". Any word other than multibyte. html ", Example:" abc.html ".
Actual Address: DISPLY.ASPX?N=ABC
2. No extension/any extension
<rewrite url= "^~/article/([^\.] +)(\.. +?)? $ "to=" ~/article/display.aspx?n=$1 "/>
Description: Maozhuxi maozhuxi.htm maozhuxi.html maozhuxi.asp. PHP maozhuxi.dfkwkfjkskdd
Actual Address: Display.aspx?n=maozhuxi
3.404 Detection
<rewriteRules>
<!--404 Detection: ~/article/maozhuxi.html--
<if url= "~/article/maozhuxi.html" exists= "~/article/maozhuxi.html" >
<forbidden/>
</if>
<rewrite url= "^~/article/([^\.] +)(\.. +?)? $ "to=" ~/article/display.aspx?n=$1 "/>
</rewriteRules>
Presence: ~/article/maozhuxi.html, will show: cannot provide this type of page
Does not exist: ~/article/maozhuxi2.html, will show: Maozhuxi2
4. IP-Sealed
<rewriteRules>
<!--IP: ~/article/maozhuxi.html--
<if url= "~/article/maozhuxi.html" address= "192.*" >
<redirect to= "~/"/>
</if>
<rewrite url= "^~/article/([^\.] +)(\.. +?)? $ "to=" ~/article/display.aspx?n=$1 "/>
</rewriteRules>
Seal: ~/article/maozhuxi.html, will: Jump to homepage (note modify the IP address in the rewrite rule)
Not sealed: ~/article/maozhuxi2.html, will show: Maozhuxi2
5. Application of String converters
<!--the application of string converters: ~/article/Chairman Mao. HTML--
<rewrite url= "^~/article/([^\.] +?) 1\.html$ "to=" ~/article/display.aspx?n=${lower ($)} "/>
<rewrite url= "^~/article/([^\.] +?) 2\.html$ "to=" ~/article/display.aspx?n=${upper ($)} "/>
Convert to lowercase: ~/article/maozhuxi1.html, display: Maozhuxi
Convert to uppercase: ~/article/maozhuxi2.html, display: Maozhuxi
6. Application of static mapping
<rewriteRules>
<mapping name= "Aihao" >
<map from= "1" to= "reading"/>
<map from= "2" to= "smoking"/>
<map from= "3" to= "Play the Game"/>
</mapping>
<!--static Mapping application: ~/article/Chairman Mao. HTML--
<rewrite url= "^~/article/([^\.] +?) (\d+?) \.html$ "to=" ~/article/display.aspx?n=${aihao:$2| Unknown} "/>
</rewriteRules>
~/article/maozhuxi1.html, will show: Reading
~/article/maozhuxi2.html, it shows: smoking
~/article/maozhuxi3.html, it will show: Play games
~/article/maozhuxi4.html, will show: unknown

Advanced article:
1. Create and use a custom action
<rewriteRules>
<!--Register Action Resolver--
<register parser= "VMoom.Framework.HttpModules.UrlRewriter.RewriteActionParser, Vmoom.framework"/>
<rewrite url= "^~/article/([^\.] +?) 1\.html$ "to=" ~/article/display.aspx?n=$1 "/>
<re url= "^~/article/([^\.] +?) (\d+?) \.html$ "to=" ~/article/display.aspx?n=$1$2 "/>
</rewriteRules>
2. Create and use a custom condition
3. Create and use a custom converter

(i), extension invariant rewrite:
Rewrite rule:
<add name= "Rewritephoto" Virtualurl= "^~/(\d+). aspx"
Rewriteurlparameter= "Excludefromclientquerystring"
Destinationurl= "~/default.aspx?id=$1"
Ignorecase= "true"/>
IIS configuration: (This configuration should be the default configuration, but some virtual host providers have modified this configuration)
Configuration (G) Property-----Properties----"Confirm File exists" check box, extension. aspx--
(b), pseudo-static rewrite, extension. html, etc.
Rewrite rule:
<add name= "Rewritephoto" Virtualurl= "^~/(\d+). html"
Rewriteurlparameter= "Excludefromclientquerystring"
Destinationurl= "~/default.aspx?id=$1"
Ignorecase= "true"/>
IIS configuration: Properties---config (G) application Extensions--
Executable file: C:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
Extension:. html
Action: Limit to Get,head,post,debug
Scripting Engine: Check
Verify that the file exists: not selected
(c), any extension of the rewrite, such as: the extension is. zxjay
Rewrite rule:
<add name= "Rewrite1" Virtualurl= "^~/(\d+). Zxjay"
Rewriteurlparameter= "Excludefromclientquerystring"
Destinationurl= "~/default.aspx?id=$1"
Ignorecase= "true"/>
IIS configuration: Ibid.
(iv) rewrite of suffix
Rewrite rule:
<add name= "Rewrite1" Virtualurl= "^~/(\d+)/default.aspx"
Rewriteurlparameter= "Excludefromclientquerystring"
Destinationurl= "~/default.aspx?id=$1"
Ignorecase= "true"/>
IIS configuration: Properties---config (G). ...-> map, wildcard application map, insert
Executable file: C:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
Verify that the file exists: not selected
The principle is that when the current directory is requested, the default document is found and the override is implemented, so "^~/(\d+)/default.aspx" in the rewrite rule corresponds to the first default document.
For more information on "Wildcard application mapping", refer to Microsoft's instructions
(v), level two domain name to multi-level domain name rewrite
(Note: Due to the constraints of the condition, the rule is not tested, theoretically can be achieved, if there are errors, please comment, thank you!) )
Rewrite rule:
<add name= "Rewrite1" Virtualurl= "^http\://(. *). Xianfen.net/default.aspx"
Rewriteurlparameter= "Excludefromclientquerystring"
Destinationurl= "~/default.aspx?id=$1"
Ignorecase= "true"/>

Urlrewriter Configuring IIS to support pseudo-static

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.