繁体   English   中英

IIS 7 URL重写规则,用于删除目录和扩展名,并且仅适用于一个目录

[英]IIS 7 url rewrite rule for removing directory and extension and specific to only one directory

我的网站中有多个目录。所有的aspx页面都在目录“ SitePages”中。 例如http://example.com/Sitepages/page1.aspx

http://example.com/Sitepages/pagexyz.aspx

我需要一个URL重写规则来剥离目录和扩展名,例如: http : //example.com/Sitepages/page1.aspx变为http://example.com/page1

如果网站位于https上,或者域名前面带有www,则该规则不应对此进行更改。

该规则还应该将用户输入的绝对URL更改为这些友好的URL。

例如,如果用户输入http://example.com/Sitepages/page1.aspx ,则浏览器应显示http://example.com/page1

所以我想需要两个规则。

此外,该规则应仅适用于目录“站点”。

该规则不应区分大小写。

我尝试了一些规则,但它们无法正常工作。 我尝试了这些:

<rule name="RewriteUserFriendlyURLS" enabled="true" stopProcessing="true">
<match url="^([a-zA-Z0-9_-]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="sitepages/{R:1}.aspx" />
</rule>

还尝试了以下方法:

<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.aspx$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="sitepages/{R:0}.aspx" />
</rule>

请帮忙。

要将用户重新分配到友好网址,您需要规则:

<rule name="Test" stopProcessing="true">
   <match url="^.*Sitepages.*\/(.*).aspx$" />
   <action type="Redirect" url="{R:1}" />
</rule>

要处理友好的URL,您需要规则:

<rule name="Test2">
   <match url="^.*Sitepages.*$" />
   <conditions logicalGrouping="MatchAll">
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
   </conditions>
   <action type="Rewrite" url="{R:0}.aspx" />
</rule> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM