[英]URL Rewrite Rule Syntax Question
我刚刚升级到VS2010 / IIS 7.5 / URL Rewrite 2.0。 我想做的事很简单,但我真的很累,想让它自己工作。
我只是想要干净的 URL,使http://example.com/abc-def.aspx变为http://example.com/abc-def/ ,从而有效地删除了.aspx扩展名并添加了斜杠。
我使用以下方法完成了此操作:
<rule name="Trim aspx for directory URLs">
<match url="(.+)\.aspx$" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
这可以正常工作并按预期重定向,但不会拉出页面,因此我认为我需要将其与Rewrite规则结合使用,以便它将干净的URL解析为相应的.aspx页面。
我试图通过使用以下方法来做到这一点:
<rule name="Add aspx extension back internally">
<match url="^http://example\.com/(.+)/$" ignoreCase="true" />
<conditions>
<add input="{URL}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern=".+/externals/.+" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
重定向规则有效,但似乎内部重写规则不起作用,因为页面没有上拉。 我究竟做错了什么?
不太确定URL Rewrite 2.0是否可以同时执行以下两种操作:
我决定要做的是在源代码中的任何地方进行更改,以指向无.aspx扩展名的URL,这样就永远不会出现以.aspx结尾的URL的外部请求。
那让我只需要:
<rule name="Add aspx extension back internally" stopProcessing="true">
<match url="(.+)/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
<rule name="Add trailing slash" stopProcessing="false">
<match url="(.*[^/])$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" pattern="favicon\.ico" ignoreCase="true" negate="true" />
<add input="{URL}" pattern="\.axd" ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" />
</rule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.