我想使用带规则部分的 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 '.
如何实现这个目标?
最佳答案
<rule name="the name" enabled="true" stopProcessing="true">
<match url="example.com/(.+)(?:/(.+)?)(.html)?"/>
<action type="Rewrite" url="lang/{R:1}/{R:2}.html"/>
</rule>
关于asp.net - 如何在多语言 ASP.NET 网站中重写 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30294528/