[英]IIS url rewrite default.aspx and other files
I just installed IIS Url Rewrite 2.0 on my IIS Server and I'm having a bit of trouble getting some of my rewrites correctly executed. 我刚刚在IIS服务器上安装了IIS Url Rewrite 2.0,但在正确执行某些重写方面遇到了一些麻烦。 Here's my trouble:
这是我的麻烦:
I want all my files to be rewrittin to: welcome.aspx > welcome/, about.aspx > about/ etc. to achieve that I'm doing this: 我希望将我的所有文件都重写为:welcome.aspx> welcome /,about.aspx> about /等,以实现我正在执行的操作:
<rule name="Remove extension with slash" stopProcessing="true">
<match url="(.*)/" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" appendQueryString="true" />
</rule>
So far that's working.. but I also have some querystring functions on default.aspx I want to be executed, when I run a URL like this: mysite.com/logout/ which really is mysite.com/default.aspx?action=logout due to this rule: 到目前为止,这是有效的..但是当我运行这样的URL时,在default.aspx上也有一些查询字符串函数要执行:mysite.com/logout/实际上是mysite.com/default.aspx?action=由于以下规则注销:
<rule name="Friendly URL" stopProcessing="true">
<match url="(.*)/" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="default.aspx?action={R:1}" appendQueryString="true" />
</rule>
But it wont execute the second rule because it will look for the logout.aspx file which does not exist, only in form of a querystring function in my default.aspx 但是它不会执行第二条规则,因为它将查找不存在的logout.aspx文件,仅在default.aspx中以querystring函数的形式
Any way I can achieve both? 有什么办法可以我做到的吗?
::::::::::: EDITS :::::::::::: ::::::::::::编辑:::::::::::::
Ive been trying all day now.. I got pretty close with the following setup: 我已经整天都在尝试。.我与以下设置非常接近:
<rule name="Remove ext" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}.aspx" matchType="IsFile" negate="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" appendQueryString="true" />
</rule>
<rule name="Default actions" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="default.aspx?action={R:1}" appendQueryString="true" />
</rule>
<rule name="Other files with querystrings" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx?action={R:2}" appendQueryString="true" />
</rule>
Almost everything works 几乎一切正常
user.aspx > user user.aspx>用户
default.aspx?action=logout > logout default.aspx?action =注销>注销
user.aspx?action=comments > user/comments user.aspx?action =评论>用户/评论
Only thing messing it up is if I add a slash after user ie. 唯一搞砸的是如果我在用户ie之后添加一个斜线。 it will respond to the default.aspx rule and act as a querystring.. which is not intented.. Any clue?
它会响应default.aspx规则并充当查询字符串。这不是故意的。有任何线索吗?
How can you expect any system to distinguish between a something that is supposed to be a page name and something that is meant as a parameter? 您如何期望任何系统区分应该作为页面名称的内容和应该作为参数的内容?
What an MVC site would do here - and your URL system is very similar to that - is to clearly define what's what. MVC网站将在此处执行的操作-您的URL系统与此非常相似-明确定义了什么。 In your case, you should use the first part (welcome, about) as the view - the page - part and add another level that would represent the method.
在您的情况下,应将第一部分(欢迎使用,关于)用作视图-页面-部分,并添加另一个表示该方法的级别。 In short, use /default/logout and rewrite this to something like
简而言之,使用/ default / logout并将其重写为类似
{R:1}.aspx?action={R:2}
If you really want to look your URLs like you said (/logout without the /default part), you could either add a rule that rewrites them individually (matched with an OR | ) or add a Logout.aspx that redirects to Default.aspx?action=logout - but that would be ugly. 如果您真的想像您所说的那样查看URL(/ logout不带/ default部分),则可以添加一个规则来单独重写它们(与OR |匹配),也可以添加一个Logout.aspx来重定向到Default.aspx。 ?action = logout-但这很丑。 Go for the clean solution.
寻求清洁的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.