The following uses a simple example for application:
First, put the downloaded intelligencia. urlrewriter. dll file in the program directory Bin
Add intelligencia. urlrewriter. dll file reference to the vs.net project.
2. Create an index. aspx File
The content of index. aspx. CS is as follows:
Protected void page_load (Object sender, eventargs E)
{
Response. Write (request ["PID"]);
}
That is to say, the PID content of the output parameter
3. Configure the Web. config file
The content is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<! -- Set the address rewriting component -->
<Configsections>
<Section name = "rewriter" requirepermission = "false" type = "intelligencia. urlrewriter. configuration. rewriterconfigurationsectionhandler, intelligencia. urlrewriter"/>
</Configsections>
<! -- Address rewriting rule file -->
<Rewriter file = "~ /App_data/Rewrite. xml "/>
<Appsettings/>
<Connectionstrings/>
<System. Web>
<Compilation DEBUG = "false">
</Compilation>
<Authentication mode = "Windows"/>
<! -- Httpmodules -->
<Httpmodules>
<Add type = "intelligencia. urlrewriter. rewriterhttpmodule, intelligencia. urlrewriter" name = "urlrewriter"/>
</Httpmodules>
</System. Web>
</Configuration>
4. Start instance application
First effect experiment:
Normal access: http: // localhost: 4412/index. aspx? PID = Hao
Rewrite the URL to http: // localhost: 4412/index_hao.aspx.
The rewrite. XML content of the rewrite rule file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Rewriter>
<! -- ([A-Za-Z] +) Only English is allowed -->
<Rewrite url = "~ /Index _ ([A-Za-Z] +). aspx $ "to = "~ /Index. aspx? PID = $1 "Processing =" stop "/>
</Rewriter>
Original access:
Rewrite:
Second effect experiment:
Normal access: http: // localhost: 4412/index. aspx? PID = Hao
Rewrite the URL to http: // localhost: 4412/index/any character. aspx
The rewrite. XML content of the rewrite rule file is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Rewriter>
<! -- ([A-Za-Z] +) Only English is allowed -->
<Rewrite url = "~ /Index _ ([A-Za-Z] +). aspx $ "to = "~ /Index. aspx? PID = $1 "Processing =" stop "/>
<! -- (. *) Any character -->
<Rewrite url = "~ /Index/(. *)/. aspx $ "to = "~ /Index. aspx? PID = $1 "/>
</Rewriter>
As follows:
The experiment is successful, isn't it easy !! You are welcome to exchange more and learn more original works from it.
Note: Use & amp; To pass multiple parameters;
For example, <rewrite url = "~ /Index/(. *)/(. *)/. aspx $ "to = "~ /Index. aspx? PID = $1 & amp; Act = $2 "/>
Supplementary instructions on converting .aspxto .html:
In fact, it is very simple. You only need to perform one step. The following uses ASP. net2.0 as an example to set it:
The executable file path is C:/Windows/Microsoft. NET/framework/v2.0.50727/aspnet_isapi.dll.
In this way, we can change the rule .aspxto .html for static access.