RewritePath() 实现简单高效的URL重写代码
2008-06-10 22:22
477 查看
//原始的URL:http://www.ccol.cn/news/12/66.aspx
//转换后URL:http://www.ccol.cn/news.aspx?q1=12&q2=66
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Regex re = new Regex(@"^((/[^/0-9]+)+)(/[0-9]+(/[^/]+)*)/.aspx$", RegexOptions.Compiled);
Match match = re.Match(HttpContext.Current.Request.Path);
if(match.Success)
{
re = new Regex(@"/([^/]+)", RegexOptions.Compiled);
MatchCollection matches = re.Matches(match.Result("$3"));
string page = match.Result("$1")+".aspx?q0="+matches[0].Result("$1");
for(int i=1; i<matches.Count; i++)
{
page += "&q"+i+"="+matches[i].Result("$1");
}
HttpContext.Current.RewritePath(page); //关键步骤
}
}
//转换后URL:http://www.ccol.cn/news.aspx?q1=12&q2=66
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Regex re = new Regex(@"^((/[^/0-9]+)+)(/[0-9]+(/[^/]+)*)/.aspx$", RegexOptions.Compiled);
Match match = re.Match(HttpContext.Current.Request.Path);
if(match.Success)
{
re = new Regex(@"/([^/]+)", RegexOptions.Compiled);
MatchCollection matches = re.Matches(match.Result("$3"));
string page = match.Result("$1")+".aspx?q0="+matches[0].Result("$1");
for(int i=1; i<matches.Count; i++)
{
page += "&q"+i+"="+matches[i].Result("$1");
}
HttpContext.Current.RewritePath(page); //关键步骤
}
}
相关文章推荐
- RewritePath() 实现简单高效的URL重写。
- 利用RewritePath和pathInfo实现URL重写及其优点
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- 示例 - 17行代码实现一个简单高效的多线程蜘蛛程序
- 利用RewritePath和pathInfo实现URL重写及其优点
- 利用RewritePath和pathInfo实现URL重写及其优点
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- DeDecms中利用关键词实现简单tag功能的php代码
- node.js 一个简单的页面输出实现代码
- JS Map 和 List 的简单实现代码
- 用VBS代码实现简单的场景恢复实例
- Python单链表简单实现代码
- springMVC简单的实现代码(一)
- JavaScript简单抽奖程序的实现及代码
- UDP实现简单的群聊功能代码示例
- 线性结构 -- 连续存储(数组), 1个简单的c语言代码实现.
- 无需太多的代码利用超链接即可实现简单自定义漂亮复选框
- 5行Python代码实现一个简单的在线英汉词典