문제

내 오래된 사이트는 더 이상 유효하지 않은 수만 개의 제품을 가지고 있었습니다. 같은 http://example.com?product_id=123456.

그들은 모두 검색 엔진 색인 지금 젠토(404)에 해결된다.나는 모든 것에 대해 리디렉션을 만들 수 없습니다.

내 홈 페이지로 해결하려면 어떻게 해야 합니까?

도움이 되었습니까?

해결책

이 경우 다음을 사용할 수 있습니다 이벤트/관찰자 그리고 이벤트에 controller_front_init_before 관찰자를 발사하십시오.

먼저 나는 이전 제품 아이디와 새 제품 아이디는 동일합니다.

그 위에 observer check query string($_서버['쿼리 문자열']) content

?제품 _이디=제품 패턴 in url 그런 다음이 기본 redirect to current system product url.

예:

가정해 봅시다.,

이전 시스템 제품: http://example.com?product_id=123456

새로운 시스템 제품: http://example.com/abx.html

내 코드는 리디렉션됩니다 http://example.com?product_id=123456http://example.com/abx.html 301 리디렉션을 사용합니다.

301 리디렉션,당신은 검색 엔진 최적화 문제를 해결합니다.

여기 구성.코드:

 <global>
    <models>
      <magento67130>
        <class>StackExchange_Magento67130_Model</class>
        <resourceModel>magento67130_mysql4</resourceModel>
      </magento67130>
    </models>
    <events>
      <controller_front_init_routers> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_front_init_before_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>magento67130/observer</class> <!-- observers class alias -->
            <method>redirectionProduct</method>  <!-- observer's method to be called -->
          </controller_front_init_before_handler>
        </observers>
      </controller_front_init_routers>
    </events>
  </global>

관찰자아래 코드는 다음과 같습니다:

<?php
class StackExchange_Magento67130_Model_Observer
{

    public function redirectionProduct(Varien_Event_Observer $observer)
    {
        return;
        if($this->_getQueryString()){
            print_r($this->_getQueryString());

                // Check query string exits in product_id
            if(strpos($this->_getQueryString(),'product_id=')!== false){
                /* get Product ifd from query string */
                 $productid=str_replace('product_id=','',$this->_getQueryString());
                if(!empty($productid)):
                $product= Mage::getModel('catalog/product')->load($productid);
                 if ($product->getId()) {
                    echo $product->getProductUrl();
                     Mage::app()->getResponse()
                        ->setRedirect($product->getProductUrl(), 301)
                             ->sendResponse();

                             return;
                 }
                endif;
            }

        }
        //die();

    }
    /* Check here Request query string */
    protected function _getQueryString()
        {
            if (!empty($_SERVER['QUERY_STRING'])) {
                $queryParams = array();
                parse_str($_SERVER['QUERY_STRING'], $queryParams);
                $hasChanges = false;
                foreach ($queryParams as $key => $value) {
                    if (substr($key, 0, 3) === '___') {
                        unset($queryParams[$key]);
                        $hasChanges = true;
                    }
                }
                if ($hasChanges) {
                    return http_build_query($queryParams);
                } else {
                    return $_SERVER['QUERY_STRING'];
                }
            }
            return false;
        }
}

다른 팁

you have to create one little custom extension to redirect if product is not found in your database

here i have given working solution and its perfect worked for me

How to forward all the 404 Magento pages to the front page?

hope this will also work for you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top