Iirf implements URL rewriting to create friendly URL links

Source: Internet
Author: User

 

 

Prerequisites: Windows servicer 2003, IIS6

Isapirewrite4.dll, isapirewrite4.ini/I have packaged them into iirf for download in csdn,

For: http://download.csdn.net/source/2019486

 

 

Step 1:

Let's first create a simple search site program

Create only one search. ASPX page

 

 

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "search. aspx. cs" inherits = "Search" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Search </title>
<SCRIPT type = "text/JavaScript" src = "Misc/JS/common/jquery. js"> </SCRIPT>
</Head>
<Body>
<Form ID = "formsearch" runat = "server">
<Div>
<Div id = "center" style = "position: relative;">
<Input type = "text" id = "txtsearchkeys" maxlength = "100" size = "46"/> <input type = "button" id = "btnsearch" value = "Search "onclick =" dosearch () "Style =" margin: 0px 5px; font-size: 14px; "/>
</Div>
<Div id = "content">
<Label>
<% = S_searchtype %>
</Label>
</Div>
</Div>
</Form>
</Body>
</Html>

 

Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Public partial class search: system. Web. UI. Page
{

Public String s_searchtype = string. empty;

Protected void page_load (Object sender, eventargs E)
{
S_searchtype = request. querystring ["searchtype"] = NULL? String. Empty: request. querystring ["searchtype"]. tostring ();
}
}

 

Different parameters are used to obtain different page results.

Http: // localhost: 8185/wt. Search/search. aspx? Searchtype = article

 

 

 

Step 2: Release the site and configure iirf

 

First create a searh site, right-click Properties, and select ISAPI filter

Add name: iirf

Append the isapirewrite4.dll provided above

 

Now we have configured isapirewrite4.ini. Note that isapirewrite4.ini and isapirewrite4.dll must be in the same directory.

 

######################################## ######

# Isapirewrite4.ini
#
# INI file for the ISAPI rewriter.
#
# An example for doing translation of JSP to Aspx. This is useful
# When doing a staged migration of a website, moving from JSP
# ASP. NET. Similar approach cocould work with ASP, PHP or other
# Server-side scripting languages ages.
#

# Date: 2010-01-24
# Author: wangtao
#

Rewritelog D:/www/search_rewritelog
Rewriteloglevel 0

### Wang Tao site search link ###

Rewritecond % {http_host} ^ search/. wangtao/. com $
Rewriterule ^/(article | product)/S-(/S * example .html $/search. aspx? Searchtype = $1 & keys = $2 [I, L, u]

Rewritecond % {http_host} ^ search/. wangtao/. com $
Rewriterule ^/$/search. aspx [I, L, u]

Rewritecond % {http_host} ^ search/. wangtao/. com $
Rewriterule ^/(article | product)/(S +). (CSS | JPG | JPEG | PNG | GIF) $/$2. $3 [I, L, u]

 

 

######################################## ######

 

 

The above is the URL rewriting rules, all of which are regular expressions. You can see it by yourself.

 

 

Step 3:

 

Now we mainly configure DNS, because there is usually no DNS server on the local machine. So we need to modify the configuration to see the effect on the local machine.

 

Searh site, right-click Properties, and select website

Click "advanced" and select "add ".

TCP port: 80

Host Header Value: search.wangtao.com // it must be consistent with the configuration file

 

We also need to hijack search.wangtao.com to parse IIS

 

Find the C:/Windows/system32/Drivers/etc/hosts file

 

127.0.0.1 localhost
127.0.0.1 search.wangtao.com // Add this line next to it,

 

Start iis now and enter http://search.wangtao.com/product/s-1.htmlor http://search.wangtao.com/article/s-1.html in the browser.

 

Both of them can be seen in vs through http: // localhost: 8185/wt. Search/search. aspx? Searchtype = article, but the current URL

 

Both Seo and users are more friendly.

 

Now you can rewrite your own URL.

 

 

 

 

 

 

 

 

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.