2011-12-12 85 views
2

我對Zend Framework非常陌生,我正在構建一個希望實施良好SEO實踐的網站。如何在Zend框架中避免糟糕的SEO重複內容網址

的URL結構將是:
example.com/language/city/controller/action

所以我在我的引導創建這條路線:

$front = Zend_Controller_Front::getInstance(); 
$router = $front->getRouter(); 
$route = new Zend_Controller_Router_Route(':language/:city/:controller/:action/*', 
             array('language'=>'es', 
               'city'=>'barcelona', 
               'controller'=>'index', 
               'action'=>'index')); 
$router->addRoute('language_city', $route); 

這我不知道是確定的,但似乎這樣的伎倆。

我注意到旁邊是所有這些網址都指向相同的內容(壞的SEO做法):

/
/es
/es/barcelona
/es/barcelona/index
/es/barcelona/index/index

有沒有辦法讓圍繞這個重複的內容問題?

在此先感謝!

回答

0

您正在設置默認值,因此對於剛好一個頁面(默認頁面),請求將是相同的。如果你刪除了默認值,如果URI不包含變量,你會得到一個錯誤(我相信404)。

$route = new Zend_Controller_Router_Route(
    ':language/:city/:controller/:action/*', 
    array('language'=>'es', //default when not in URI 
      'city'=>'barcelona', //default when not in URI 
      'controller'=>'index', //default when not in URI 
      'action'=>'index' //default when not in URI 
    ) 
); 

好像你可能想刪除默認值languagecity,因爲沒有數據我不知道你的控制器要做的事情。

如果你這樣做,唯一的「複製」的URI將是:

/es/barcelona 
/es/barcelona/index 
/es/barcelona/index/index 

你只需要使用這些URI之一。如果您使用Zend的View_Helper_Url輸出鏈接,則會將index/index關閉 - 因爲它與默認值相匹配。

您可以隨時添加其他路線來映射其他請求(例如/)到相關控制器。

還應注意,如果你只有一個控制器處理所有這些「城市」的要求,你並不需要把它的URI

$route = new Zend_Controller_Router_Route(
    ':language/:city/:action/*', 
    array('language'=>'es', //default when not in URI 
      'city'=>'barcelona', //default when not in URI 
      'controller'=>'index', //all requests route here 
      'action'=>'index' //default when not in URI 
    ) 
); 

那麼唯一的「重複的URI是:

/es/barcelona 
/es/barcelona/index 
+0

非常感謝Tim!現在已經很清楚了。問候。 – XeL

+0

@XeL很高興幫助 - 可能值得看看各種路由器類型。如果你正在做基本的CRUD,我發現REST路由器很有用。 –