惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
B
Blog
博客园_首页
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
量子位
V
V2EX
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
I
InfoQ
博客园 - 【当耐特】

博客园 - Eric Yao

当前几个主要的Lucene中文分词器的比较 jquery radio,checkbox,select操作 - Eric Yao .NET开发十大必备工具 基于.net开发平台项目案例集锦 实现FCKeditor 多用户分文件夹上传图片等附件 网络蜘蛛C#开源示例 全球知名CMS系统清单 网站优化中的多域名问题 计算机端口大全 简化软件操作,提升用户体验 切换CSS换皮肤 Asp.net关于Header/title/Meta tages/Style操作的小技巧 UML学习笔记(2) UML学习笔记(1) 对面向对象设计原则的总结 修改 3389 端口终端 十二款世界顶级杀毒软件下载---有序列号全可免费升级 GDI+中对图片的裁剪 收集得最全的sql 语句
对于URL重写,支持无后缀url请求
Eric Yao · 2007-06-26 · via 博客园 - Eric Yao

 有些资料讲如果要支持目录必须使用iiswriter,或者其他软件,其实通过简单对iis配置,再利用urlwriter就可以完美解决url重写的问题

可以将http://abc.domain.com/blog

转向到http://www.domain.com/xxx.aspx?username=abc

当然首先要将主机的泛域名支持打开。

做法是

A。打开IIS,右击站点(虚拟目录)-》属性-》主目录-》配置-》插入-》C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,不确认文件存在-》确定

B。修改webconfig:

  <RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>http://127.0.0.1/(blog)</LookFor>
        <SendTo>~/list.aspx?tag=$1</SendTo>
      </RewriterRule>
   </Rules>
</RewriterConfig>

C。修改UrlRewriter
从微软下载源码,

1.BaseModuleRewriter.cs

protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e) 
        

            HttpApplication app 
= (HttpApplication) sender; 
            Rewrite(app.Request.Path, app); 
        }
 

改为

protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e) 
        

            HttpApplication app 
= (HttpApplication) sender; 
            Rewrite(app.Request.Url.AbsoluteUri, app); 
        }

就是将  app.Request.Path 替换成了  app.Request.Url.AbsoluteUri

2.ModuleRewriter.cs

for(int i = 0; i < rules.Count; i++
            

                
// get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory) 
                string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$"
 
                
// Create a regex (note that IgnoreCase is set) 
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase); 
 
                
// See if a match is found 
                if (re.IsMatch(requestedPath)) 
                

                    
// match found - do any replacement needed 
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo)); 
 
                    
// log rewriting information to the Trace object 
                    app.Context.Trace.Write("ModuleRewriter""Rewriting URL to " + sendToUrl); 
 
                    
// Rewrite the URL 
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl); 
                    
break;        // exit the for loop 
                }
 
            }
 

改为

for(int i = 0; i < rules.Count; i++
            

                
// get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory) 
                string lookFor = "^" + rules[i].LookFor + "$"
 
                
// Create a regex (note that IgnoreCase is set) 
                Regex re = new Regex(lookFor, RegexOptions.IgnoreCase); 
 
                
// See if a match is found 
                if (re.IsMatch(requestedPath)) 
                

                    
// match found - do any replacement needed 
                    string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo)); 
 
                    
// log rewriting information to the Trace object 
                    app.Context.Trace.Write("ModuleRewriter""Rewriting URL to " + sendToUrl); 
 
                    
// Rewrite the URL 
                    RewriterUtils.RewriteUrl(app.Context, sendToUrl); 
                    
break;        // exit the for loop 
                }
 
            }
 

string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$";

改成了

string lookFor = "^" + rules[i].LookFor + "$";