2011-12-01 102 views
0

我正在遷移一個網站,但新網站是cPanel中的一個「插件」域,它以子目錄的形式提交給主網站。如何使用301重定向.htacess網站的一個頁面到另一個頁面中的子目錄?

所以,我該怎麼辦的301重定向舊網站的一個頁面,在同一頁上的新網站考慮到上述?

我已經試過

Redirect 301 /page1.php http://www.newsite.com/page1.php 

但是,這使得在page1.php中新網站進入無限循環。

任何想法?

回答

1

以下添加到您的.htaccess文件在你的舊域名的根目錄

RewriteEngine On 
RewriteBase/

# if request is on the old domain 
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ 
#for page1.php, then redirect it to new domain 
RewriteRule ^page1.php$ http://www.newdomain.com/page1.php [L,R=301] 

# or use below to redirect any php page to the new domain 
RewriteRule ^(.+).php$ http://www.newdomain.com/$1.php [L,R=301] 

編輯: 如果你想在舊網站到新網站一切重定向然後使用下面的代碼。

RewriteEngine On 
RewriteBase/

# if request is on the old domain 
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ 
RewriteRule (.*) http://www.newdomain.com/$1 [L,R=301] 

如果你只想重定向的舊主頁上新與

#just redirect the home page 
RewriteRule ^$ http://www.newdomain.com/ [L,R=301] 
+0

由於更換上述重寫規則!第二種解決方案是在遷移時違反Google的最佳做法,因此我將採用第一種解決方案,該解決方案很有效。但是,如何重定向主域名以便www.oldsite.com重定向到www.newsite.com?我嘗試使用「index.php」進行重定向,但只有在您實際將/index.php添加到舊網站的域時纔有效。有任何想法嗎? – ProgrammerGirl

+0

見上 –

+0

我的編輯爲什麼你需要使用'OD rewrite'?不能通過'redirect 301'完成嗎? (我不知道答案,我只是好奇爲什麼......)@UlrichPalha –

相關問題