UrlRewriter - a rule-based URL Rewriter for .NET.
Copyright (c)2007 Seth Yates
Author Seth Yates
Version 2.0 RC 1 build 6
Installation
============
1. Open your web project, or create a new one.
2. Add a reference to the Intelligencia.UrlRewriter assembly.
3. Open the web.config file.
4. Add Configuration section handler:
<configSections>
<section
name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
This enables the URL Rewriter to read its configuration from the rewriteRules node in the
web.config file.
5. Add UrlRewriter mapper HttpModule:
<system.web>
<httpModules>
<add
type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
name="UrlRewriter" />
</httpModules>
</system.web>
This enables the URL Rewriter to intercept web requests and rewrite URL requests.
6. Add some rules to your web.config file:
When using wildcard mapping and handling all web requests using ASP.NET, the default document settings in IIS are lost. Here¡¯s a rule you can add at the bottom of your rule set which will give you back default document handling:
<rewrite url=¡±^(.*)/(\?.+)?$¡± to=¡±$1/default.aspx$2?¡± />
Note that using processing=¡±restart¡± will rerun the URL back through your rule base in case you have any earlier rules that depend on /default.aspx.
If you want to support multiple default documents like IIS does, then your default document rule will need to be a bit more complex:
<if url=¡±^(.*)/(\?.+)?$¡±>
<rewrite exists=¡±$1/default.aspx¡± to=¡±$1/default.aspx$2¡å />
<rewrite exists=¡±$1/index.aspx¡± to=¡±$1/index.aspx$2¡å />
<rewrite exists=¡±$1/index.html¡± to=¡±$1/index.html$2¡å />
</if>
Be careful adding too many of these, as the file existence check is non-trivial.
Again, if you are using wildcard mapping and having ASP.NET handle every request, then you will discover that you need to add a rule to stop processing of file types that you do not want to handle (images, etc). A rule like the following at the very top of your rule set will
immediately stop rewriting anything with the extension .gif, .png,
.jpg, .ico, .pdf, .css or .js. Your situation may vary so you may want
to add other extensions:
<rewrite url=¡±^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$¡±
to=¡±$1¡å processing=¡±stop¡± />
Two regular expression characters that are typically included (but not required) are the ^ and the $. ^ means the beginning of the URL, while $ means the end of the URL. Adding these at the beginning and ending of your pattern just ensures that you¡¯re matching what you intend to match.
Using the ~/ convention if you may install your application in different web application roots (e.g., sometimes at /myapp1 and other times at /someotherplace). This way, you will not have to have different rules if your application is installed in a different virtual folder name (or even in the root of the web site).
One very useful convention is to include an optional pattern to match querystrings. If you don¡¯t do this, then people could break your rewriting by adding a query string (?abc=123, etc).
The pattern I typically use has one of two forms:
(1) If the target url doesn¡¯t have a custom query string:
<rewrite url=¡±^~/mypage(\?.+)?$¡± to=¡±~/default.aspx$1¡å />
Here $1 matches (\?.+)? which matches the entire querystring.
(2) If the target url does have a custom query string:
<rewrite url=¡±^~/mypage(\?(.+))?$¡± to=¡±~/default.aspx?page=mypage&$2¡å />
Here, you have to use & because this is an XML file and it requires the & to be escaped properly. $2 relates to (.+) which will be the querystring without the ?.
Recommended reading
<rewriter>
<if url="/tags/(.+)" rewrite="/tagcloud.aspx?tag=$1" />
<!-- same thing as <rewrite url="/tags/(.+)" to="/tagcloud.aspx?tag=$1" /> -->
</rewriter>
The syntax of the rewriter section is very powerful. Refer to the help file for more details
of what is possible. The above rule assumes you have mapped all requests to the .NET runtime.
For more information on how to do this, see http://urlrewriter.net/index.php/using/installation/
7. Compile and test!
没有合适的资源?快使用搜索试试~ 我知道了~
全球最著名的Url重写组件 UrlRewriter.NET
共92个文件
cs:78个
xml:3个
txt:3个
需积分: 10 25 下载量 102 浏览量
2010-09-11
14:13:13
上传
评论
收藏 179KB ZIP 举报
温馨提示
灵活的URL重写可以让你的网站增加可用性和专业性。在帮助网站更好的被搜索引擎索引收录方面,这也是一个重要的因素。在本篇文章中,我将带你了解如何在ASP.NET中简单的实现URL重写,以及一些常见问题的解决办法。我还将说明为什么URL重写如此重要,以及如何使用它来增强你的网站。什么是URL重写? URL重写就是首先获得一个进入的URL请求然后把它重新写成网站可以处理的另一个URL的过程
资源推荐
资源详情
资源评论
收起资源包目录
urlrewriternet20rc1b6.zip (92个子文件)
UrlRewriterV2
bin
Debug
Intelligencia.UrlRewriter.dll 60KB
Intelligencia.UrlRewriter.dll.PermCalc.xml 73KB
Intelligencia.UrlRewriter.pdb 234KB
Release
Intelligencia.UrlRewriter.dll 56KB
Intelligencia.UrlRewriter.xml 92KB
License.txt 1KB
Readme.txt 1KB
src
Rewriter
Parsers
RewriteActionParser.cs 3KB
IfConditionActionParser.cs 3KB
SetCookieActionParser.cs 2KB
IRewriteConditionParser.cs 950B
IRewriteActionParser.cs 1KB
UrlMatchConditionParser.cs 1KB
NotFoundActionParser.cs 2KB
PropertyMatchConditionParser.cs 1KB
AddHeaderActionParser.cs 2KB
SetStatusActionParser.cs 2KB
RedirectActionParser.cs 2KB
MethodConditionParser.cs 1KB
ForbiddenActionParser.cs 2KB
RewriteActionParserBase.cs 3KB
ExistsConditionParser.cs 1KB
SetPropertyActionParser.cs 2KB
GoneActionParser.cs 1KB
NotAllowedActionParser.cs 2KB
AddressConditionParser.cs 1023B
UnlessConditionActionParser.cs 911B
NotImplementedActionParser.cs 2KB
HeaderMatchConditionParser.cs 1KB
RewriterHttpModule.cs 3KB
UrlRewriter.ndoc 4KB
UrlRewriter.snk 596B
RewriteFormHtmlTextWriter.cs 2KB
Utilities
IContextFacade.cs 3KB
Constants.cs 3KB
TypeHelper.cs 2KB
MessageProvider.cs 1KB
HttpContextFacade.cs 4KB
Message.cs 805B
IPRange.cs 4KB
Messages.resx 4KB
Intelligencia.UrlRewriter.csproj 12KB
RewriterEngine.cs 14KB
RewriteContext.cs 5KB
Logging
NullLogger.cs 1KB
IRewriteLogger.cs 1KB
DebugLogger.cs 2KB
RewriteProcessing.cs 633B
Intelligencia.UrlRewriter.xml 92KB
Configuration
ConditionParserPipeline.cs 876B
RewriterConfigurationReader.cs 9KB
RewriterConfiguration.cs 7KB
RewriterConfigurationSectionHandler.cs 870B
ActionParserFactory.cs 2KB
TransformFactory.cs 1KB
Errors
DefaultErrorHandler.cs 941B
IRewriteErrorHandler.cs 363B
Transforms
LowerTransform.cs 1KB
Base64DecodeTransform.cs 882B
DecodeTransform.cs 846B
EncodeTransform.cs 846B
Base64Transform.cs 885B
UpperTransform.cs 1017B
StaticMappingTransform.cs 1KB
IRewriteTransform.cs 656B
FormRewriterControlAdapter.cs 663B
Conditions
AddressCondition.cs 1KB
ExistsCondition.cs 1KB
PropertyMatchCondition.cs 2KB
UrlMatchCondition.cs 2KB
IRewriteCondition.cs 751B
NegativeCondition.cs 1KB
MethodCondition.cs 1KB
MatchCondition.cs 1KB
Actions
NotImplementedAction.cs 522B
GoneAction.cs 481B
IRewriteAction.cs 1KB
RewriteAction.cs 2KB
MethodNotAllowedAction.cs 531B
SetCookieAction.cs 2KB
NotFoundAction.cs 498B
ConditionalAction.cs 2KB
AddHeaderAction.cs 2KB
ForbiddenAction.cs 501B
SetStatusAction.cs 1KB
SetLocationAction.cs 1KB
SetPropertyAction.cs 2KB
RedirectAction.cs 2KB
Form.cs 3KB
AssemblyInfo.cs 946B
Intelligencia.UrlRewriter.sln 2KB
Readme.txt 4KB
共 92 条
- 1
资源评论
huanghaohhh
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功