1
我爲Windows服務器上承載的項目使用標準web.config文件。它需要處理2個任務。web.config索引重定向
- 它將網站的非www版本重定向到www版本。
- 它將索引文件重定向到根。
見下文:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="index\.asp(?:l)?" />
<conditions>
<add input="{HTTP_HOST}" pattern="example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/" />
</rule>
<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
這個偉大的工程,除1個問題。索引重定向將所有子目錄重定向到主索引。
例如:
http://www.example.com/index.asp像它應該被重定向到http://www.example.com。
但是,http://www.example.com/about/index.asp也重定向到http://www.example.com。我想它重定向到http://www.example.com/about/
任何幫助將不勝感激。
不錯的工作和感謝張貼! – worked 2012-08-25 23:50:27