2011-07-22 79 views
2

我最近從我的所有頁面中刪除了.php擴展名。將所有以.php結尾的URL重定向到無分機

谷歌的結果仍顯示:

www.mysite.com/page.php 
www.mysite.com/directory/page-example.php 

現在這些死鏈接。新的有:

www.mysite.com/page 
www.mysite.com/directory/page-example 

什麼是適當的重定向,這樣,如果有人點擊該網址.PHP之一,他們在重定向到無擴展名的URL

回答

7
  1. 使用<link rel="canonical" href="FULL_PROPER_URL" />您網頁。這會告訴搜索引擎在顯示搜索結果時使用該網址,並在查看重複網址時將其視爲主要網址。詳情請看這裏:

  2. 使用301永久重定向。請注意,這不會阻止Google或任何其他搜索引擎請求.php頁面,如果此類鏈接在某些其他網站上公開可用。

這需要放在網站根文件夾中的.htaccess文件中。如果放置在其他地方,可能需要進行一些調整。

Options +FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase/

# redirect to .php-less link if requested directly 
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+ 
RewriteRule ^(.+)\.php $1 [R=301,L] 

上述規則將做301重定向到一個無php的URL。它只會在直接請求.php文件時重定向,並且不會觸及已重寫的URL。

+0

好回答@​​LazyOne – Andrew

相關問題