2015-02-07 46 views
0

我創建了一個Wordpress網站,它是舊網站的更新版本。舊網站已經在谷歌搜索中有一些高的鏈接,我想創建htaccess中的舊頁面重定向到新的(域保持不變)。例如,我有這樣的使用htaccess在Wordpress中重定向頁面

/index.php?event=newsdetails&news_id=139&parent_id=4&menu_id=1 

一個鏈接,我想它重定向到這個

/blog/my/link 

我怎麼能這樣做?它是否可行?是否可以在任何域上運行(例如,新站點現在在測試域中)? 這裏是我的htaccess的文件,但它不工作的方式我想:

RewriteEngine On 
RewriteBase/

#RewriteCond %{HTTP_HOST} ^(www\.)?pchig\.pl$ [NC] 
#RewriteRule !^pl/ /pl%{REQUEST_URI} [L,NC] 

RewriteRule ^index\.php$ - [L] 

# add a trailing slash to /wp-admin 
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] 
RewriteRule . index.php [L] 

#Redirections 
RewriteRule ^/index.php?event=newsdetails&news_id=140&parent_id=4&menu_id=1(\/.*)?$ /blog/my/link [R=301,L] 
+0

是什麼/博客/我的/鏈接?這並不明確。 'blog'是一個子目錄嗎?不要把'/ blog/my/link'這樣的例子,這沒有幫助。把你期望的鏈接看作你的問題中新網站的瀏覽器。 – 2015-02-08 05:53:11

+0

新鏈接應該是永久鏈接。例如/ blog/new-in-china – JayKey 2015-02-08 09:15:12

回答

0

你可以嘗試添加一個301重定向到你的.htaccess文件:

redirect 301 /old/old.html http://www.new.com/new.html 

注意:不要添加「http://www」到 聲明的第一部分 - 將您站點頂層 的路徑放到頁面上。另外,還要確保你離開這些元素之間一個空格 :

重定向301(指示該頁面已移動)

/old/old.htm(原始文件夾路徑和文件名)

http://www.new.com/new.htm(新路徑和文件名)

當搜索引擎的蜘蛛再次您的網站,他們將跟隨 您在.htaccess文件創建的規則。 搜索引擎蜘蛛實際上沒有讀取 .htaccess文件,但將 服務器的響應識別爲有效。

在下次更新期間,舊文件名和路徑將爲 丟棄並替換爲新的文件名。有時您可能會在 期間看到交替的舊/新文件名,以及排名的一些波動。根據Google的 Google需要6-8周的時間才能看到在您的網頁上反映了 的更改。


如果要將所有文件重定向您的域名,如果你是一個UNIX Web服務器上使用您的 .htaccess文件:

redirectMatch 301 ^(.*)$ http://www.example.com 
redirectMatch permanent ^(.*)$ http://www.example.com 

您也可以使用其中的一個在你的.htaccess文件:

redirect 301 /index.html http://www.example.com/index.html 
redirect permanent /index.html http://www.example.com/index.html 
redirectpermanent /index.html http://www.example.com/index.html 

這將使用 「的index.html」 重定向到另一個域中的 301-感動永久重定向。

如果需要http://example.com重定向到 http://www.example.com和你 您的服務器上得到了mod_rewrite的啓用,你可以把這個在你的。htaccess文件:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example\.com 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L] 

或本:

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
RewriteRule ^(.*)$ http://www.exmaple.com/$1 [R=301,L]