IIRF 實現url 重寫打造友好的url連結

來源:互聯網
上載者:User

 

 

準備條件:windows servicer 2003,IIS6

IsapiRewrite4.dll,IsapiRewrite4.ini  /這兩樣我已經打包成IIRF在CSDN的下載裡面提供下載,

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

 

 

第一步:

我們先來建立一個簡單的搜尋的網站程式

只建立一個Search.aspx頁面

 

 

<%@ 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();
    }
}

 

我們通過不同的參數就可以得到不同的頁面結果

http://localhost:8185/WT.Search/Search.aspx?searchtype=article

 

 

 

第二步,我們將發布網站,並配置IIRF

 

先建立一個Searh的網站,右擊屬性,選擇ISAPI篩選器

添加名稱 :IIRF

將上面的我提供的IsapiRewrite4.dll附加進去

 

現在我們來配置IsapiRewrite4.ini 了,要注意IsapiRewrite4.ini要和IsapiRewrite4.dll要在同一目錄下面

 

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

# 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 to
# ASP.NET. Similar approach could work with ASP, PHP or other
# server-side scripting languages.
#

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

RewriteLog  D:/www/Search_RewriteLog
RewriteLogLevel 0

### 王濤網站搜尋連結 ###

RewriteCond    %{HTTP_HOST}    ^search/.wangtao/.com$
RewriteRule    ^/(article|product)/s-(/S*).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]

 

 

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

 

 

上面就是就是URL重寫的規則,都是一些Regex。自己多看看就懂了

 

 

第三步:

 

現在主要來配置DNS了,因為一般在本機上面是沒有DNS伺服器的。所以我們要在本機上面看到效果就還需要修改一點配置

 

Searh的網站,右擊屬性,選擇網站

點擊進階,選擇添加

tcp 連接埠:80

主機頭值:search.wangtao.com //這裡要和設定檔的一致

 

我們現在還需要劫持search.wangtao.com給IIS解析

 

找到C:/WINDOWS/system32/drivers/etc/hosts 檔案

 

127.0.0.1       localhost
127.0.0.1       search.wangtao.com  //在後面新增這一行就行了,

 

現在啟動IIS,在瀏覽器裡面輸入http://search.wangtao.com/product/s-1.html或http://search.wangtao.com/article/s-1.html

 

都可以看到和我們在VS裡面能過http://localhost:8185/WT.Search/Search.aspx?searchtype=article看到的一樣的效果,但是現在的URL

 

不管是對SEO還是使用者都是更加友好。

 

好了現在就可以打造屬於你自己的URL重寫了。

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.