2012-12-21 125 views
0

当前我正在使用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> 

但这种方式似乎不能够重定向整个网址。有什么建议么? 感谢

* UPDATE

尝试使用下面的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> 

回答

0

为什么不使用重定向方法?

private void Page_Load(object sender, System.EventArgs e) 
{ 
    response.redirect("http://newdomain.com/page1/topic1"); 
} 
+1

嗨,我无法硬编码URL路径。例如,当用户通过搜索引擎搜索链接时,我需要将特定的url与整个路径一起重定向到新的域。 – My2ndLovE

相关问题