开发者

Magento Popular Search Results - How to get them to do 301 redirects when setting a redirect in Admin

开发者 https://www.devze.com 2023-03-04 10:44 出处:网络
It LOOKS like I tracked down an issue I\'m having with magento popular search results, but I\'m going nuts trying to get them to redirect properly.

It LOOKS like I tracked down an issue I'm having with magento popular search results, but I'm going nuts trying to get them to redirect properly.

OK, here's the situation. I don't mind Magento's popular search results queries in the SE's index. Alot of times, the customer inputs something that can be helpful for search. My problem is when a customer types into the search bar the exact same terms as a category or products. This creates duplicate content issues, so I redirect these query terms in the Magento Admin.

However, these redirects are 302 temporary redirects, when they really should be 301.

I tracked down a file in Mage > CatalogSearch > controllers > ResultController.php that has the following code on line 65

if ($query->getR开发者_StackOverflow社区edirect()){
                $query->save();
                $this->getResponse()->setRedirect($query->getRedirect());                    
                return;
            } 

I think that somewhere here, there should be a ->setHttpResponseCode(301)

But so far, I can't get a 301 redirect response anywhere.

I can certainly do this in htaccess, but it would be a lot easier if set programmatically.


If you are sure, that the if block really is being entered, this one should work:

if ($query->getRedirect()){
    $query->save();
    $this->getResponse()->setRedirect($query->getRedirect(), 301);                    
    return;
}

I assume that $this->getResponse() contains an Mage_Core_Controller_Response_Http instance. See its superclass method Zend_Controller_Response_Abstract::setRedirect().

EDIT:

If you want to define permanent redirects using the backend, goto Catalog -> URL Rewrite Management -> Edit URL Rewrite -> Redirect -> Permanent (301).

0

精彩评论

暂无评论...
验证码 换一张
取 消