ASP.NET 除 root 之外的所有页面的 httpRedirect exactDestination
ASP.NET httpRedirect exactDestination for all pages except root
我正在更改 IIS 网站的主域,我需要保持现有 URL 正常工作。同时,我正在更改此(以前的)域的起始页的行为。这个域以前可以在其根级别访问,但现在我需要根页面(默认文档)重定向到特定的子目录。
总结:我需要在重定向时保留除默认文档 (root) 之外的所有页面的尾随路径。示例:
www.old.com/
-> www.new.com/en
www.old.com/en/page2.htm
-> www.new.com/en/page2.htm
www.old.com/en/page3.htm
-> www.new.com/en/page3.htm
www.old.com/page1.htm
-> www.new.com/page1.htm
我有这个web.config
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://www.new.com" httpResponseStatus="Permanent" exactDestination="false" />
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.new.com/en" httpResponseStatus="Permanent" exactDestination="true" />
</system.webServer>
</location>
</configuration>
我已将 IIS 设置 默认文档 设置为 Default.aspx
。
但这不起作用。
我通过使用 IIS 中的 URL 重写模块解决了这个问题:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Root request" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="http://www.new.com/en" redirectType="Found" />
</rule>
<rule name="Path request" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<action type="Redirect" url="http://www.new.com/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我正在更改 IIS 网站的主域,我需要保持现有 URL 正常工作。同时,我正在更改此(以前的)域的起始页的行为。这个域以前可以在其根级别访问,但现在我需要根页面(默认文档)重定向到特定的子目录。
总结:我需要在重定向时保留除默认文档 (root) 之外的所有页面的尾随路径。示例:
www.old.com/
->www.new.com/en
www.old.com/en/page2.htm
->www.new.com/en/page2.htm
www.old.com/en/page3.htm
->www.new.com/en/page3.htm
www.old.com/page1.htm
->www.new.com/page1.htm
我有这个web.config
:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://www.new.com" httpResponseStatus="Permanent" exactDestination="false" />
</system.webServer>
<location path="Default.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://www.new.com/en" httpResponseStatus="Permanent" exactDestination="true" />
</system.webServer>
</location>
</configuration>
我已将 IIS 设置 默认文档 设置为 Default.aspx
。
但这不起作用。
我通过使用 IIS 中的 URL 重写模块解决了这个问题:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Root request" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="http://www.new.com/en" redirectType="Found" />
</rule>
<rule name="Path request" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<action type="Redirect" url="http://www.new.com/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>