【发布时间】:2015-05-18 03:12:13
【问题描述】:
我想使用带有规则部分的 Web.config 重写我的 asp.net 多语言网站中的 URL。
我有如下网址:
http://example.com/lang/en/index.html、http://example.com/lang/fr/index.html等
我需要删除 lang 和 .html 扩展并将 url 重写为:
http://example.com/en/index, http://example.com/fr/index
我的 Web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteHTML">
<match url="(.*)" />
<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:1}.html" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="lang/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
所以如果我去'http://example.com/en/index',我需要打开这个页面:'http://example.com/lang/en/index.html'。
如何实现这个目标?
【问题讨论】:
标签: asp.net url-rewriting