[英]URL Rewrite Rule Syntax Question
I've just upgraded to VS2010 / IIS 7.5 / URL Rewrite 2.0. 我刚刚升级到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. 我只是想要干净的 URL,使http://example.com/abc-def.aspx变为http://example.com/abc-def/ ,从而有效地删除了.aspx扩展名并添加了斜杠。
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. 这可以正常工作并按预期重定向,但不会拉出页面,因此我认为我需要将其与Rewrite规则结合使用,以便它将干净的URL解析为相应的.aspx页面。
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?
我究竟做错了什么?
Not really sure if there is a way with URL Rewrite 2.0 to do both: 不太确定URL Rewrite 2.0是否可以同时执行以下两种操作:
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. 我决定要做的是在源代码中的任何地方进行更改,以指向无.aspx扩展名的URL,这样就永远不会出现以.aspx结尾的URL的外部请求。
That allowed me to only need: 那让我只需要:
<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.