I actually combat this using a core controller over-ride. Without this, Google could in-theory penalise you for duplicate content as it will see the HTTPS AND HTTP versions of your site, having the same content. I've written a blog post on it, but I've not posted it yet - but basically, Magento includes the functionality to redirect you to a HTTPS page when required (i.e. checkout, account area etc) however, it doesn't provide the opposite.
This approach has the added benefit of not needing to alter your .htaccess file each time that you add a new secure URL. It also means, you don't miss anything.
The function is called in app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
. Luckily, as this is a Controller file, it means that we can copy it to our local folder, and over-ride the method. So, copy app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
to app/code/local/Mage/Core/Controller/Varien/Router/Standard.php
.
In Magento 1.7 and 1.8, you need to look at the function _checkShouldBeSecure
- around line 427 of your newly copied file.
Alter this function to:
protected function _checkShouldBeSecure($request, $path='')
{
if (!Mage::isInstalled() || $request->getPost()) {
return;
}
if ($this->_shouldBeSecure($path) && !Mage::app()->getStore()->isCurrentlySecure()) {
$url = $this->_getCurrentSecureUrl($request);
Mage::app()->getFrontController()->getResponse()
->setRedirect($url)
->sendResponse();
exit;
} elseif (!$this->_shouldBeSecure($path) && Mage::app()->getStore()->isCurrentlySecure()) {
$url = $this->_getCurrentUnsecureUrl($request);
Mage::app()->getFrontController()->getResponse()
->setRedirect($url)
->sendResponse();
exit;
}
}
Now, add the function:
protected function _getCurrentUnsecureUrl($request)
{
if ($alias = $request->getAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS)) {
return Mage::getBaseUrl('link', false).ltrim($alias, '/');
}
return Mage::getBaseUrl('link', false).ltrim($request->getPathInfo(), '/');
}