Tuesday, February 21, 2012

Magneto Removal of "/" for Duplicate Link

For SEO reasons store owners will often want to standardise the URL generation in their Magento store.so sometime duplicate link generate for the same page
Ex: :yourdomain.com/contactus/
       yourdomain.com/contacts

Both will open the same page but why two link it is not standard for SEO purpose
So,for removing "/" from url we need to update changes in the following files



Firstly lets modify the getUrl() method to remove any trailing slashes in generated URLs. Copy the file app/code/core/Mage/Core/Block/Abstract.php to app/code/local/Mage/Core/Block/Abstract.php if it's not there already.

Open app/code/local/Mage/Core/Block/Abstract.php and find the getUrl() method, it should just be one line of code that returns the requested URL:

return $this->_getUrlModel()->getUrl($route, $params);

Replace that line with the following:
$return_url = $this->_getUrlModel()->getUrl($route, $params);
if ($return_url != $this->getBaseUrl() && substr($return_url, -1) == '/' && !Mage::getSingleton('admin/session')->isLoggedIn()):
    return substr($return_url, 0, -1);
else:
    return $return_url;
endif;

Next Copy the file app/code/core/Mage/Core/Model/Url.php to app/code/local/Mage/Core/Model/Url.php if it's not there already.

Open app/code/local/Mage/Core/Model/Url.php and find the following:
if ($noSid !== true) {
    $this->_prepareSessionUrl($url);
}
A little further up the file the variable $noSid is initialised:
$noSid = null;

and change the if statement from:
if ($noSid !== true) {
to
if ($noSid === false) {

Open .htaccess and find the following rule:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Immediately after this add the following lines:
RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,R=301]

and when u open yourdomain.com/contactus/  it will redirect to yourdomain.com/contacts so this will remove the duplication of links
Hope this will help you

No comments:

Post a Comment

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...