Due to SEO reasons, a common problem that Magento has is that it
indexes two URLs of the same page which causes issues with duplicate
content when it comes to Google crawling. For example it will index both
of these URLs.
http://www.magentosite.com/category.html/
and
http://www.magentosite.com/category.html
Ideally, we would like to stop Magento adding trailing slashes to the end of the URLs and then redirect it to the page without the trailing slash, and here’s how.
app/code/core/Mage/Core/Block/Abstract.php
To
app/code/local/Mage/Core/Block/Abstract.php
Now open Abstract.php and find the following line of code:
to
app/code/local/Mage/Core/Model/Url.php.
Once you’ve done that open it and find the following code:
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Add the following immediately underneath it:
RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,R=301]
http://www.magentosite.com/category.html/
and
http://www.magentosite.com/category.html
Ideally, we would like to stop Magento adding trailing slashes to the end of the URLs and then redirect it to the page without the trailing slash, and here’s how.
Lets begin
To start with we need to edit the getURL() method to stop it generating URLs with trailing slashes, so copy the following file from:app/code/core/Mage/Core/Block/Abstract.php
To
app/code/local/Mage/Core/Block/Abstract.php
Now open Abstract.php and find the following line of code:
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;Now copy the file app/code/core/Mage/Core/Model/Url.php
to
app/code/local/Mage/Core/Model/Url.php.
Once you’ve done that open it and find the following code:
if ($noSid !== true) { $this->_prepareSessionUrl($url); }Change ($noSid !== true) to ($noSid == false)
Edit your .HTACCESS file
Find the following line of code:RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Add the following immediately underneath it:
RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} !^/downloader.*$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,R=301]
No comments:
Post a Comment