Urlrewrite, address ing technology (the legendary "iis url rewriting ")

Source: Internet
Author: User

What is the use of urlrewrite?
1. Meet Search Engine Requirements
Some search engines cannot capture dynamic pages, and a large amount of information cannot be searched by potential users. With urlrewrite technology, you can
Http: // server/news. asp? Id = 111 to http: // server/news/111.htm
In this way, they will be indexed by search engines. Although Google can capture dynamic pages, Google generally scores dynamic pages less than static pages. Therefore, for websites with a large amount of information published
It is absolutely worthwhile to change the website address to static.
2. Hiding Technology to Improve website portability
Every page is marked with a clear. asp/. JSP development language. You can see at a glance what language your website uses. When changing the website language, you need to change a lot
Link. In addition, if a page has modified its extension, its PageRank will also disappear from the beginning. We can use urlrewrite technology to hide our implementation details, so that we can modify and Port
It is convenient, and PageRank is not lost at all.
3. satisfying aesthetic requirements
For website designers who are pursuing perfection, even the addresses of webpages must look concise and clear. Shape

Http: // server/news. asp? Channel = 3 & id = 111

The webpage address is definitely not eye-catching by the perfectionist. With urlrewrite technology, you can turn it
Http: // server/news/3/111.htm.

1. download the isapi_rewrite.isapi_rewrite lite and full versions. the lite version does not support rewriting of each virtual host site and can only be processed globally. however, for friends with servers, the lite version is enough. http://www.helicontech.com/download/ Lite version

That is
Isapi_rewrite 3 lite freeware!

Read
On specific limitations
(You can also select the appropriate one)

2. Install the. MSI file, just like the general program, and install it in D:/program files/helicon/isapi_rewrite3/
.
3. The next step is important. Open Internet Information Service, right-click Web site properties, click the ISAPI Filter tab, Add filter, enter the name, specify isapi_rewrite.dll in the path, and click OK.
(If IIS is 6.0 and isapi_rewrite is
The software will be automatically added when a later version is installed, and an isapi_rewrite tab will be added to the web site attribute. The earlier version needs to be manually added. (haha, my version is later.
)

4. Test. Create a test. asp file.
<% = Request. querystring ("info") %>
The result is test. asp? Info = manually entered content (the page will be displayed)
5. This step is very important. Add Rewrite Rules (that is, rewriterule)
Open Internet Information Service, right-click website properties, and click isapi_rewrite.
Tab,
Open edit. Copy the following code and save it.
(We want to test. asp? Infographic hello is of the test-hello.html type ),
Rewriterule/test-([0-9, A-Z] * example .html/test. asp /? Info
= $1

Click application and save
6. Check the effect in the browser. Enter http: // localhost/test. asp? Info = Hello
And http: /localhost/test-hello.html
Is the displayed content all hello
? This proves the success! (If not, restart IIS and try again)

Note: in this way, I modify the server configuration (there is no way to do it without my own server). We recommend a new method (implemented using code )!

Method 2: Use httpmodule to implement URL rewriting
Use the httpcontext. rewritepath method provided by ASP. NET. This method allows developers to dynamically rewrite the processing path of the received URL, and then allow ASP. NET to continue executing the request using the previously rewritten path. For example, you can show the following URLs to the public:

Http://www.store.com/products/Books.aspx

Http://www.store.com/products/DVDs.aspx

Http://www.store.com/products/CDs.aspx

In the outside world, the website has three separate webpages (this looks great for search crawlers ). Use
Httpcontext's rewritepath method. When these requests enter the server, we can dynamically rewrite the received URL to a single products. aspx Network
The page contains the category name or pathinfo parameter of a query string. For example, we can use
Application_beginrequest:
Void
Application_beginrequest (
Object
Sender, eventargs e ){

String
Fullorigionalpath
=
Request. url. tostring ()
;

If
(Fullorigionalpath. Contains (
"/Products/books. aspx"
)){

Context. rewritepath (
"/Products. aspx? Category = books"
)
;

}

Else if
(Fullorigionalpath. Contains (
"/Products/DVDs. aspx"
)){

Context. rewritepath (
"/Products. aspx? Category = DVDs"
)
;

}

}

The disadvantage of coding such as the above is that it is boring and easy to make mistakes. I suggest you do not write it by yourself. Instead, you can use the online httpmodule to complete this task. Here are a few free httpmodules that you can download and use now:
Urlrewriter.net
Urlrewriting.net

These modules allow you to declare matching rules in the web. config file of your application. For example, use
The urlrewriter. Net module maps the above URLs to a single products. ASPX page. We only need to add this web. config file to our
In the application (no encoding is required ):


<? XML version = "1.0"?>

<Configuration>

<Configsections>
<Section name = "rewriter" requirepermission = "false"
Type = "intelligencia. urlrewriter. configuration. rewriterconfigurationsectionhandler,
Intelligencia. urlrewriter "/>
</Configsections>

<System. Web>

<Httpmodules>
<Add name = "urlrewriter" type = "intelligencia. urlrewriter. rewriterhttpmodule, intelligencia. urlrewriter"/>
</Httpmodules>

</System. Web>

<Rewriter>
<Rewrite url = "~ /Products/books. aspx "to = "~ /Products. aspx? Category = books "/>
<Rewrite url = "~ /Products/CdS. aspx "to = "~ /Products. aspx? Category = CDS "/>
<Rewrite url = "~ /Products/DVDs. aspx "to = "~ /Products. aspx? Category = DVDs "/>
</Rewriter>

</Configuration>

The above httpmodule URL rewriting module also supports regular expressions and URL pattern matching (to avoid your
File ). Therefore, you do not need to write a category name. You can rewrite the matching rule as follows to dynamically combine the category name from any/products/[category]. aspx
URL:


<Rewriter>
<Rewrite color: Red "> aspx" to = "~ /Products. aspx? Category = $1 "/>
</Rewriter>


This makes your code extremely clean and scalable.

Sample download

Note: (1) Pay attention to some images and CSS paths.
(2) do not forget to upload Web. config to the server.

(3) If you want to rewrite HTML, You need to configure it in IIS to transfer the HTML file to Asp.net for processing!

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.