2012-09-20 39 views
2

我試圖將所有不存在的頁面重定向到不同的域,因爲我的博客被移到了不同​​的域。Intelligencia URLRewriter不存在或非aspx頁面

所以www.mydomain.com/blog/asdf應該重定向到blog.mydomain.com/blog/asdf

使用Intelligencia URLRewriter模塊我也可以把博客/但如果我做博客/什麼我得到一個404

即使沒有這樣一個正則表達式的簡單規則,它沒有博客文件夾

<rewrite url="~/blog/^" to="http://blog.softwaresynergy.com/blog/" /> 

我也試過這件T下任何工作o強制所有請求去處理器

<modules runAllManagedModulesForAllRequests="true"> 

有關如何在博客/ /重定向到其他域的所有內容的任何想法?

+0

你使用IIS嗎? – turtlepick

+0

是的,但它是一個共享託管服務,所以我無法直接在IIS中修改任何內容。需要全部通過網絡配置。 – xmorera

回答

0

試着用以下的重定向規則:

<redirect url="^/blog/(.+)$" to="http://blog.softwaresynergy.com/blog/$1" /> 

把它放在你的其他重寫規則上面,所以它最先被執行,我認爲它應該工作。

+0

同樣的問題,在本地工作,但不在主機上。是否有安全限制? – xmorera

+0

您可能會碰到這個http://urlrewriter.net/index.php/support/installation/limitations – Nelson

+0

也許,但我使用共享主機。我可以通過配置嗎? – xmorera

0

URL重寫不允許重寫其他域或子域上的路徑。您可以在global.asax中使用此代碼重定向網址:

void Application_BeginRequest(object sender, EventArgs e) 
{ 
    string path = Request.Path; 
    if (path.Contains("blog/")) 
    { 
     HttpContext.Current.Response.Redirect("http://blog.softwaresynergy.com/blog/"); 
    } 
} 
+0

我將這種技術用於規範重定向,即添加www。但它不適用於PHP頁面或文件夾。 – xmorera

0

使用自定義404頁面。

<system.webServer> 
    <httpErrors existingResponse="Replace" errorMode="Custom"> 
     <remove statusCode="404"/> 
     <error statusCode="404" path="/Custom404.aspx" responseMode="Redirect" /> 

<customErrors mode="On"> 
      <error statusCode="404" redirect="/custom404.aspx" /> 

在custom404頁面中,我把代碼做我的重定向。獲取引起錯誤很可能是一個組合的路徑...

Request.QueryString("aspxerrorpath"); 
Request.UrlReferrer; 

一旦我有他們試圖訪問的路徑只是做一個重定向。

Response.Redirect(NEW_SITE + PATH, true); 
0

我以不同的方式做了改變。將原始網站留作php,並使用php重寫進行重定向,這很好。

在new.mydomain我做的ASPX網站

不理想,但現在工作的領域。