Redirect all HTTP urls to HTTPS for frontend in magento

Redirect all HTTP urls to HTTPS for frontend in magento

August 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Redirect all HTTP urls to HTTPS for frontend in magento

Redirecting Magento Front-End HTTP URLs to HTTPS

In Magento, you can easily configure secure URLs for front-end pages. However, this setting only applies to pages shown after login or checkout. If you want to redirect all non-secure (HTTP) URLs to secure (HTTPS) ones specifically for the front-end without affecting your admin panel, follow these steps:

Why Secure URLs Matter

Securing your Magento store’s front-end is crucial for several reasons:

  • Customer Trust: HTTPS ensures that data transmitted between your site and customers’ browsers remains private.
  • SEO Benefits: Search engines like Google consider HTTPS as a ranking factor. Redirecting to secure URLs can boost your SEO performance.
  • Prevents Data Theft: Secure URLs protect sensitive customer information, like login credentials or payment details.

How to Redirect Magento Front-End HTTP URLs to HTTPS

While Magento provides built-in settings for using secure front-end URLs, they don’t cover all scenarios. In this case, we’ll use an .htaccess rule that targets only the front-end by checking if a request is not part of the admin area.

Step 1: Create a Custom .htaccess File

Open your terminal and navigate to your Magento root directory. Create a new file named custom.htaccess:

cd /path/to/magento/root/directory
touch custom.htaccess

Open this new file for editing:

nano custom.htaccess

Step 2: Add the Custom Rewrite Rules

Copy and paste the following rules to your custom.htaccess file:

# Redirect HTTP requests from front-end pages only
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(index.php|admin) [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Prevent the admin area from being redirected to HTTPS
RewriteCond %{REQUEST_FILENAME} !^/pub/
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/admin/$1 [L]

Save and close the file by exiting with Ctrl + X, then pressing Y to confirm, followed by Enter.

What These Rules Do

  • The first rule redirects all non-secure (HTTP) requests for pages that aren’t part of the admin area or index.php.
  • The second rule ensures that your admin panel remains on HTTP even if a request is secure.

Testing Your Redirects

Ensure that your front-end pages redirect to HTTPS when accessed via HTTP, while your admin panel stays unchanged:

  1. Access any product page using http://yourdomain.com/product-page

  2. Confirm you’re redirected to the secure version: https://yourdomain.com/product-page

  3. Now try accessing the admin panel with http://yourdomain.com/admin

  4. Observe that it remains on the non-secure HTTP connection.

Conclusion

Securing your Magento store’s front-end URLs is a best practice for maintaining customer trust and improving SEO performance. By using custom .htaccess rules, you can ensure that only the front-end pages are redirected to HTTPS, leaving your admin panel unaffected.

Remember to backup your existing .htaccess file before making changes. If any issues arise, you can always revert to the original configuration.

At Laravel Company, we specialize in helping businesses optimize their e-commerce platforms for enhanced security and performance. Contact us today to learn more about our Magento development services: laravelcompany.com.

Checkout Performance Admin Configuration

Our network