URL 重写规则语法问题
我刚刚升级到 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>
效果很好,并按预期重定向,但没有拉出页面,所以我认为我需要将其与重写规则结合起来,以便它将干净的 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>
重定向规则有效,但内部重写规则似乎不起作用,因为页面没有拉起。我做错了什么?
I've just upgraded to VS2010 / IIS 7.5 / URL Rewrite 2.0. What I want to do is pretty easy I'd imagine, but I'm really tired of trying to get this to work on my own.
I simply want clean URLs, whereby http://example.com/abc-def.aspx becomes http://example.com/abc-def/, effectively removing the .aspx extension and adding a trailing slash.
I've done that by using:
<rule name="Trim aspx for directory URLs">
<match url="(.+)\.aspx$" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
That works just fine and redirects as intended, but doesn't pull up the page so I thought I needed to combine that with a Rewrite rule so that it will resolve the clean URL to the corresponding .aspx page.
I've tried to do that by using:
<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>
The Redirect Rule works, but it seems as though the internal Rewrite Rule doesn't work because the page doesn't pull up. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定是否有办法使用 URL Rewrite 2.0 来完成这两项操作:
我决定做的是更改源代码中的所有位置,使其指向无 .aspx 扩展名的 URL,这样就永远不会有以 .aspx 结尾的 URL 传入的外部请求。
这让我只需要:
Not really sure if there is a way with URL Rewrite 2.0 to do both:
What I decided to do was change everywhere in source to point to the .aspx extension-less URLs so that there should never be an outside request coming in with a URL ending in .aspx.
That allowed me to only need: