2012-12-21 170 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

相關問題