Go to: Classic URL rewriting

Source: Internet
Author: User
Urlrewriter is a URL rewriting component encapsulated by Microsoft. Step 1: download this component. Decompress the package and copy urlrewriter. DLL to your project bin directory. Step 2: Add the following content to Web. config: <? XML version = "1.0" encoding = "gb2312"?>
<Configuration>
<Configsections>
<Section name = "rewriterconfig" type = "urlrewriter. config. rewriterconfigserializersectionhandler, urlrewriter"/>
</Configsections> Step 2: add the rewritten rule node:
For example:
<Rewriterconfig>
<Rules>
<Rewriterrule>
<Lookfor> ~ /Examples/(. [0-9] *) \. html </lookfor>
<Sendto> ~ /Search/search_sell.aspx? Id = $1 </sendto>
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /Logs/search_logs \. aspx </lookfor>
<Sendto> ~ /Search/search_sell.aspx </sendto>
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /Buy/(. [0-9] *) \. html </lookfor>
<Sendto> ~ /Search/search_buy.aspx? Id = $1 </sendto>
</Rewriterrule>
<Rewriterrule>
<Lookfor> ~ /Buys/(. [0-9] *) \. html </lookfor>
<Sendto> ~ /Buys/show. aspx? Id = $1 </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig> This depends on your needs. If you are not familiar with regular expressions, there is no way to find the regular expression based on your high IQ, you can use it with a few changes. Haha. If you cannot figure it out, Google the regular expression. (I started to guess by referring to other people's configurations. I used it right, huh, huh. Later I read the relevant information and found it useful .) Step 3: add the module configuration (written in <system. Web> ):
For example:
<Httphandlers>
<Add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
</Httphandlers>
(HTTP Program To process the rewrite) Well, now we can try it. So the input: http: // 127.0.0.1: 8080/Hangzhou/1. aspx appears. However, if it is changed to: http: // 127.0.0.1: 8080/Hangzhou/1.html
Dizzy. Khan...
The reason is that we didn't use Asp.net's ISAPI to parse HTML parsing.
The solution is... Step 4: add an extension item with the same configuration as the ASPX page in IIS \ your site \ properties \ main directory \ Configuration \. Note: Do not select "check whether the file exists". Otherwise, the file cannot be found. Try again now. What? #¥ % # ¥ %. Haha. Don't worry. Let's take a look at it. We didn't configure. html in Web. config and used this module for parsing. Step 5: add the following to the module configuration:
<Httphandlers>
<Add verb = "*" Path = "*. aspx" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
<Add verb = "*" Path = "*. html" type = "urlrewriter. rewriterfactoryhandler, urlrewriter"/>
</Httphandlers> it's okay now. I am so excited. Don't worry, it's just the simplest. If your page has a return request. For example, if you put the DataGrid on the page and there are pages, you will find that the page goes down to the next page, and then you will find a problem again.
What should I do now? In fact, I have mentioned it on Microsoft's website. I will briefly describe it here.

Step 6: add the component for form return Persistence:
Find actionlessform. dll in the project you downloaded and put it in the bin directory of your project. Then add the following to your page:
<% @ Register tagprefix = "SKM" namespace = "actionlessform" assembly = "actionlessform" %>
Change <form...>:
<SKM: Form ID = "Your form name" method = "Post" runat = "server">
.....
</SKM: Form> that's all. Now you can rest assured. Everything is as you wish. Finally, I wish you all the best. Multiple parameters:
Web. config
<Rewriterrule>
<Lookfor> ~ /Product/SUB/y/([A-Za-z0-9 \ s] +)/([A-Za-z0-9 \ s] +) \. html </lookfor>
<Sendto> ~ /Product/sub_category.aspx? Txt_l0 = $1 & amp; txt_l1 = $2 & amp; showbrand = Y </sendto>
</Rewriterrule>

Related Article

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.