2010-08-20 151 views
2

我有一個像Asp.net URL重寫(正則表達式)

http://somedomain.com/products.aspx?id=1

的網址,我想改寫這個像

somedomain.com/productname

其餘域中的URL按照提供的方式工作。 像

somedomain.com/forums/categories.aspx

我不希望重寫這些其他網址。

+0

什麼版本的.NET?你正在使用什麼URL重寫庫? – 2010-08-20 17:37:39

+0

我正在使用此示例, http://www.codeproject.com/KB/aspnet/urlrewriter.aspx 實際上,我是新的url重寫,如果有人可以建議我任何其他簡單的方法,我會明白, 。 謝謝 – user426594 2010-08-20 18:01:04

+0

鑑於codeproject的例子,你不是在尋找「somedomain.com/product1.aspx」嗎?即......即代替「?id = 1」。 – Rusty 2010-08-20 18:43:15

回答

0

做這樣的烏爾global.ascx文件從

其中u [R重定向此,有頁面u能做到這樣有

的Response.Redirect( 「somedomain.com/productname」);

void Application_BeginRequest(object sender,EventArgs e) string fullOrigionalpath = Request.Url.ToString();

string[] words = fullOrigionalpath.Split('/'); 
    string d = words[words.Length-1].ToString(); 
    if (!d.EndsWith("aspx")) 
    { 
     Context.RewritePath("/products.aspx?id=1); 
    } 

} 
+0

它不僅僅是產品頁面, 其他頁面也可以稍後重寫。 所以,這就是爲什麼我想通過正則表達式來處理這個問題。 \t \t \t \t /URLRewriterM/s/h/o/w/(.*)\.html \t \t \t \t /URLRewriterM/show.aspx?id=$1 \t \t \t user426594 2010-08-21 11:27:53