我想使用带有规则部分的Web.config在我的asp.net多语言网站中重写URL。
我的网址如下:
http://example.com/lang/en/index.html
,http://example.com/lang/fr/index.html
等
我需要删除lang
和.html
扩展名并将网址重写为:
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>
所以如果我去&#39; http://example.com/en/index&#39;我需要打开此页面:&#39; http://example.com/lang/en/index.html&#39;。
如何实现这一目标?
答案 0 :(得分:0)
<script type="text/javascript">
var unavailableDates = <%= this.calls() %>
</script>
答案 1 :(得分:0)
[增订] 最后它解决了。这是Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<customErrors mode="On" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Ignore" enabled="true" stopProcessing="true">
<match url="^(js|css).*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.html$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^\/(?!#.*).*" />
<action type="Rewrite" url="lang/{R:0}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
特别感谢Ashkan Mobayen Khiabani&#34;忽略&#34; part(需要忽略:javaScript,Images和CSS文件夹以保持链接正常工作)