Forcing HTTPS in Magento and Checking for Secure URLs in Code

Forcing HTTPS in Magento and Checking for Secure URLs in Code

Every store should run entirely over HTTPS. In Magento 1 that is two settings, plus a couple of helpers for custom code.

Admin settings

In System > Configuration > General > Web > Secure, set both Use Secure URLs in Frontend and Use Secure URLs in Admin to Yes, and make sure the secure base URL starts with https://.

Building a secure URL

<?php 
Mage::getBaseUrl('url', $secure = true);
?>

Checking the current request

Useful when a block should behave differently on secure pages:

<?php 
if (Mage::app()->getStore()->isCurrentlySecure()) {
    echo 'Current URL is Secure';
} else {
    echo 'Current URL is NOT Secure';
}

?>

Heads up: this guide applies to Magento 1, which stopped receiving official security updates in June 2020. If your store still runs it, plan a move to Magento 2 or Adobe Commerce soon. We can help with the migration.

Stuck on something similar? Our Magento development team is happy to take a look.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.