【发布时间】:2016-12-15 09:13:52
【问题描述】:
我想在 ASP.Net 中使用 Intelligencia.UrlRewriter.RewriterHttpModule 进行 URL 重写,这是我在 web.config 中的以下配置
> <configSections>
> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,
> Intelligencia.UrlRewriter" /> </configSections>
在 system.web 中
<httpModules>
<add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />
</httpModules>
我想要以下类型的网址
site.com/home site.com/contact site.com/info site.com/page/innerpage site.com/in/info
为此我分别写了以下规则
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^Home$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="\.aspx$" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Default.aspx" />
</rule>
<rule name="RewriteUserFriendlyURL2" stopProcessing="true">
<match url="^contact$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="contact.aspx" />
</rule>
<rule name="RewriteUserFriendlyURL3" 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="info.aspx?keyword={R:1}" />
</rule>
<rule name="Rewrite to page.aspx">
<match url="^pages/([^/]+)" />
<action type="Rewrite" url="page.aspx?page={R:1}" />
</rule>
<rule name="Rewrite to info.aspx">
<match url="([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="info.aspx?keyword2={R:1}&keyword={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
<rewriter>
</rewriter>
一切正常,但如果使用我习惯获取的最后一条规则并且 CSS / javascript 停止工作,我尝试了许多解决方案来解决 css/javascript/image 规则的暗示但没有奏效。
site.com/in/info
<rule name="Rewrite to info.aspx">
<match url="([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="info.aspx?keyword2={R:1}&keyword={R:2}" />
</rule>
【问题讨论】:
标签: c# asp.net url-rewriting web-config url-rewrite-module