目前我正在使用 Windows 共享主机。我需要将我的子域重定向到一个新域(包括整个路径)。
例如,当用户访问http://oldsubdomain.olddomain.com/page1/topic1时,它会将用户重定向到http://newdomain.com/page1/topic1
这是我的服务提供商建议的方法
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
但是这种方式似乎无法重定向整个 url。有什么建议么?谢谢
*更新
尝试使用如下 web.config 进行重定向,但仍然得到 500 内部错误,知道吗?
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rule name="CName to URL" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.olddomain\.com$" />
</conditions>
<action type="Redirect" url="http://newdomain.com/{R:0}" />
</rule>
</rewrite>
</system.webServer>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>