2012-08-02 79 views
0

我google至少有3個小時,並嘗試所有的例子在堆棧溢出和其他論壇。 有誰知道如何使用.htaccess(重定向或重寫)能夠將所有流量從一個域重定向到另一個域,而不會在.com之後傳遞任何內容?重定向整個請求到新的域名,沒有後續的原始請求.com後的任何內容

我有一個老域名:

http://www.olddomain.com 

我想所有的請求到該域重定向到一個特定的URL

http://www.newdomain.com/new/directory/ 

我試圖重定向的相當多的種類和重寫規則.htaccess,但如果我提出如下請求:

http://www.olddomain.com/some/directory/ 

重定向總是出現在新域如:

http://www.newdomain.com/new/directory/some/directory/ 

重定向是等待重定向的URI後。

我試過添加?在新網址的末尾,這並沒有幫助。

這是我的一些重定向。 (域名更改爲保護無辜者)

RewriteEngine on 

#RewriteRule^http://www.newdomain.com/new/directory/ [R=301,L] 
#RewriteRule^http://www.newdomain.com/new/directory/? [R=301,L] 
#RewriteRule /?$ http://www.newdomain.com/new/directory/? [R=301,L] 
RewriteRule ^([^/\.]+)/?$ http://www.newdomain.com/new/directory/? [R=301,L] 

我嘗試了重定向命令,以及...

Redirect 301/http://www.newdomain.com/new/directory/? 

這些都不似乎刪除/一些/目錄/和自顧自地重定向到

http://www.newdomain.com/new/directory/some/directory/ 

任何想法將非常感激。

回答

0

儘量只:

RedirectMatch 301^http://www.newdomain.com/new/directory/? 

但是,如果你寧願使用mod_rewrite,它看起來像你是非常接近你的規則,它只是需要有正則表達式匹配什麼

RewriteRule^http://www.newdomain.com/new/directory/? [R=301,L] 

有一個警告,如果這兩個域實際上託管在同一個服務器上,同一個文檔根,並且你將把它放在一個htaccess文件中,那麼你需要在上面添加一個額外的檢查RewriteRule爲主機:

RewriteCond %{HTTP_HOST} olddomain.com$ [NC] 
相關問題