Forcing Magento to Not Use SSL on Homepage
As an experienced developer writing for Laravel Company, I often encounter cases where Magento is configured to use SSL on the homepage by default, leading to issues like “insecure content” warnings when certain modules are installed. This guide will walk you through the process of disabling SSL usage specifically for your home page.
Understanding the Issue
By default, Magento 2 sets the web/cookie/cookie_domain and web/cookie/cookie_httponly configuration values to require all pages to use SSL. If you have a module that generates content with non-SSL URLs (like images), this can cause security warnings on browsers.
Step-by-Step Solution
1. Verify Your Current Configuration
First, let’s check your current web settings in the Magento admin panel:
// Go to Stores > Settings > Configuration
Look for the following sections:
Web: This contains SSL-related settings.Cookies: Here you’ll find cookie domain and httponly options.
Make note of the values, especially the web/secure flag. It should be set to ‘No’ if you want to disable SSL for your homepage.
2. Modify the .htaccess File
The .htaccess file in your Magento root directory controls some of the redirection and SSL settings. You’ll need to modify this file:
// Open the .htaccess file using a text editor or SSH
Look for the section that starts with RewriteEngine On. Within this section, you should find something like this:
# RewriteRule ^(?!index.php|robots.txt|favicon.ico) index.php [L]
The line after this comment is where we’ll make our changes. Add the following exception for your homepage URL (replace https://example.com with your actual domain):
RewriteCond %{REQUEST_URI} !^/index.php$ [NC]
RewriteCond %{HTTP_HOST} ^(?!www\.|dev\.)example\.com$ [NC,OR]
RewriteRule ^(?!index.php|robots.txt|favicon.ico) index.php [L]
This tells Apache to ignore the SSL check for your homepage.
3. Update Your Configuration XML
Next, you need to update the app/etc/config.xml file:
// Open the config.xml file using a text editor or SSH
Find the <web> section and look for the <secure> node. Change its value from ‘1’ to ‘0’:
<web>
<secure>0</secure> // Set this to 0
...
</web>
This disables the SSL requirement globally, but remember that you should still enable it for other sensitive pages like checkout.
Conclusion
By following these steps, you should now have successfully forced Magento to not use SSL on your homepage. Remember, this solution is a quick fix and does not address the underlying issue of using non-SSL resources in your modules. It’s always best practice to ensure all your content (including images) uses SSL for better security.
If you’re facing more complex issues with your Magento setup or need help with custom module development, don’t hesitate to reach out to our team at Laravel Company. We provide expert consultation and development services tailored to your business needs.