最近在做一个 cms 手机网站, 由于内容不是很多, 很快做完了. 空闲的时间考虑 seo, 想把 url 全部写成静态的. 在查资料的时候, 发现 UrlRewrite.NET 这个组件非常的不错, 尝试了下结果达到了理想的效果.
1, 通过 nuget 安装该类库;
2, 注册为后缀 html 的路由;
3,web.config 配置;
- <!-- 在 configuration 节点下配置 -->
- <configSections>
- <section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter" />
- </configSections>
- <!-- 在 system.webServer 节点下配置 -->
- <modules runAllManagedModulesForAllRequests="true">
- <remove name="UrlRoutingModule" />
- <add name="UrlRoutingModule" type="UrlRewrite.RewriteModule, UrlRewrite" preCondition="managedHandler" />
- </modules>
4, 生成 url 链接的时候添加上后缀, 如果使用, 如果是使用 @HTML.ActionLink("主页", "Index", "Home") 这方式生成, 会自动生成带后缀. HTML;
5, 测试访问;
到此就可以了, 这样比较有利于 seo;
来源: http://www.bubuko.com/infodetail-3478638.html