2012-10-25 2 views
1

클라이언트 용으로 개발중인 사이트에서 일부 SEO 피드백을 받았습니다.Magento HTTP HTTPS 페이지의 표준 태그

기본적으로 사이트는 http 및 https 페이지의 색인을 생성합니다.

나는 백 엔드에서 표준 태그를 사용하도록 설정했습니다. 중복을 제거하려면 https 페이지를 참조하는 Canonical 태그를 제거하고 해당 http Canonical 태그로 바꾸는 것이 좋습니다.

Magento에 내장 된 기능입니까, 아니면 내 모듈을 만들어야하며 페이지 요청 유형을 확인하고 그런 식으로 태그를 삽입해야합니까?

답변

1

) 헤더에 다중 태그를 추가했다. 내 코드가

protected function _prepareLayout() 
{ 
parent::_prepareLayout(); 

$this->getLayout()->createBlock('catalog/breadcrumbs'); 

if ($headBlock = $this->getLayout()->getBlock('head')) { 
    $category = $this->getCurrentCategory(); 
    if ($title = $category->getMetaTitle()) { 
    $headBlock->setTitle($title); 
    } 
    if ($description = $category->getMetaDescription()) { 
    $headBlock->setDescription($description); 
    } 
    if ($keywords = $category->getMetaKeywords()) { 
    $headBlock->setKeywords($keywords); 
    } 
    if ($this->helper('catalog/category')->canUseCanonicalTag()) { 
    if(isset($_SERVER['HTTPS'])) { 
     $pattern  = '/((ht){1}(tps://))/'; 
     $replacement = 'http://'; 
     preg_replace($pattern, $replacement, $category->getUrl()); 
     $headBlock->addLinkRel('canonical', $category->getUrl()); 
    } else { 
     $headBlock->addLinkRel('canonical', $category->getUrl()); 
    } 
    } 
    /* 
    want to show rss feed in the url 
    */ 
    if ($this->IsRssCatalogEnable() && $this->IsTopCategory()) { 
     $title = $this->helper('rss')->__('%s RSS Feed',$this->getCurrentCategory()->getName()); 
     $headBlock->addItem('rss', $this->getRssLink(), 'title="'.$title.'"'); 
    } 
} 

return $this; 
} 
0

기본적으로 브라우저의 주소 표시 줄은 https이지만 표준 태그는 여전히 http 여야합니다.

브라우저의 주소 표시 줄에 https 및 http 버전을 입력 한 다음 각 버전의 페이지 소스를보고 헤더 섹션에서 표준 태그 (href 값)를 검색하십시오. https가 아닌 동일해야합니다.

문제가 있으면 사용중인 magento 버전을 알려주십시오.

<?xml version="1.0"?> 
<config> 
    <modules> 
     <RWS_ProductCanonical> 
      <version>0.1.0</version> 
     </RWS_ProductCanonical> 
    </modules> 

    <global> 
     <blocks> 
      <productcanonical> 
       <class>RWS_ProductCanonical_Block</class> 
      </productcanonical> 
      <catalog> 
       <rewrite> 
        <category_view>RWS_ProductCanonical_Block_Category_View</category_view> 
       </rewrite> 
      </catalog> 
     </blocks> 
     <helpers> 
      <productcanonical> 
       <class>RWS_ProductCanonical_Helper</class> 
      </productcanonical> 
     </helpers> 
    </global> 
</config> 

블록 응용 프로그램/코드를 생성 할 블록을 확장하려면/지역/RWS/ProductCanonical/차단/카테고리/View.php (나는 Mage_Core_Block_Template을 확장하고있는 확장 할 때 때문에 모든 코드를 복사 난 그냥 단지 _prepareLayout 기능을 필요로하는 Mage_Catalog_Block_category_View 확장되면서 Mage_Catalog_Block_Category_View는

class RWS_ProductCanonical_Block_Category_View extends Mage_Core_Block_Template 
{ 
    protected function _prepareLayout() 
    { 
     parent::_prepareLayout(); 

     $this->getLayout()->createBlock('catalog/breadcrumbs'); 

     if ($headBlock = $this->getLayout()->getBlock('head')) { 
      $category = $this->getCurrentCategory(); 
      if ($title = $category->getMetaTitle()) { 
       $headBlock->setTitle($title); 
      } 
      if ($description = $category->getMetaDescription()) { 
       $headBlock->setDescription($description); 
      } 
      if ($keywords = $category->getMetaKeywords()) { 
       $headBlock->setKeywords($keywords); 
      } 
      if ($this->helper('catalog/category')->canUseCanonicalTag()) { 
       ////// add to header here 
       $headBlock->addLinkRel('canonical', $category->getUrl() . '?limit=all'); 
      } 
      /* 
      want to show rss feed in the url 
      */ 
      if ($this->IsRssCatalogEnable() && $this->IsTopCategory()) { 
       $title = $this->helper('rss')->__('%s RSS Feed',$this->getCurrentCategory()->getName()); 
       $headBlock->addItem('rss', $this->getRssLink(), 'title="'.$title.'"'); 
      } 
     } 

     return $this; 
    } 

    public function IsRssCatalogEnable() 
    { 
     return Mage::getStoreConfig('rss/catalog/category'); 
    } 

    public function IsTopCategory() 
    { 
     return $this->getCurrentCategory()->getLevel()==2; 
    } 

    public function getRssLink() 
    { 
     return Mage::getUrl('rss/catalog/category',array('cid' => $this->getCurrentCategory()->getId(), 'store_id' => Mage::app()->getStore()->getId())); 
    } 

    public function getProductListHtml() 
    { 
     return $this->getChildHtml('product_list'); 
    } 

    /** 
    * Retrieve current category model object 
    * 
    * @return Mage_Catalog_Model_Category 
    */ 
    public function getCurrentCategory() 
    { 
     if (!$this->hasData('current_category')) { 
      $this->setData('current_category', Mage::registry('current_category')); 
     } 
     return $this->getData('current_category'); 
    } 

    public function getCmsBlockHtml() 
    { 
     if (!$this->getData('cms_block_html')) { 
      $html = $this->getLayout()->createBlock('cms/block') 
       ->setBlockId($this->getCurrentCategory()->getLandingPage()) 
       ->toHtml(); 
      $this->setData('cms_block_html', $html); 
     } 
     return $this->getData('cms_block_html'); 
    } 

    /** 
    * Check if category display mode is "Products Only" 
    * @return bool 
    */ 
    public function isProductMode() 
    { 
     return $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_PRODUCT; 
    } 

    /** 
    * Check if category display mode is "Static Block and Products" 
    * @return bool 
    */ 
    public function isMixedMode() 
    { 
     return $this->getCurrentCategory()->getDisplayMode()==Mage_Catalog_Model_Category::DM_MIXED; 
    } 

    /** 
    * Check if category display mode is "Static Block Only" 
    * For anchor category with applied filter Static Block Only mode not allowed 
    * 
    * @return bool 
    */ 
    public function isContentMode() 
    { 
     $category = $this->getCurrentCategory(); 
     $res = false; 
     if ($category->getDisplayMode()==Mage_Catalog_Model_Category::DM_PAGE) { 
      $res = true; 
      if ($category->getIsAnchor()) { 
       $state = Mage::getSingleton('catalog/layer')->getState(); 
       if ($state && $state->getFilters()) { 
        $res = false; 
       } 
      } 
     } 
     return $res; 
    } 
} 
+0

안녕하세요, 1.7 버전입니다. 자세한 내용은 카테고리 페이지의 https 태그 만 볼 수 있습니다. 당신이 말하는 것처럼 제품은 모두 http 태그를 사용합니다. –

+0

제품 세부 정보 페이지에서 제대로 작동하지만 카테고리 페이지에서 모두 https라고 말하고 있습니까? 방금 1.7 버전을 사용해 보았습니다 (하지만 기본 버전을 곧 확인하도록 맞춤 수정을 많이했습니다) –

+0

제품 페이지는 http 또는 https 페이지에 액세스 할 때 http 정식을 사용합니다. 카테고리 페이지는 https 페이지에 액세스 할 때 https 표준 태그를 표시하고 http 페이지를 통해 http 표준 태그에 액세스합니다. 나는 http 정식 태그를 사용하여 중복을 생각하는 Google을 멈추게 할 필요가 있습니다. 희망이 의미가 있습니다. –