RewritePath() 实现简单高效的URL重写。
2008-05-30 12:50
330 查看
//原始的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重写代码
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- 利用RewritePath和pathInfo实现URL重写及其优点
- 利用RewritePath和pathInfo实现URL重写及其优点
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- 利用RewritePath和pathInfo实现URL重写及其优点
- 快速实现简单高效并可以灵活配置的URL重写方案(附源代码)
- Apache Mod_Rewrite实现URL重写的配置方法
- discuz论坛Apache Rewrite实现URL重写的配置方法
- Apache Mod_Rewrite实现URL重写的配置方法
- ISAPI_Rewrite实现Asp伪静态及URL重写
- 使用ISAPI_Rewrite对asp.net实现URL重写,显示HTML后缀
- 简单高效的分块记录的实现
- 文件初始化简单高效的分块记录的实现
- 分享一个.NET实现的简单高效WEB压力测试工具
- 简单高效的实现Android App全局字体替换
- Android RenderScript 简单高效实现图片的高斯模糊效果
- nginx实现url重写-rewrite实例参考
- 玩转nodeJS系列:使用原生API实现简单灵活高效的路由功能(支持nodeJs单机集群),nodeJS本就应该这样轻快
- 简单 3 步实现高效编程