Solving Magento HTTPS Issues: Redirecting to Specific Pages
If you’re facing issues with Magento 1.9.1 not properly redirecting HTTP URLs to their corresponding HTTPS versions, you’ve come to the right place. In this article, we’ll dive into your specific problem and provide a step-by-step solution.
The Problem Recap
You want all pages on your subfolder /shop/ to be accessible via HTTPS. Currently, when trying to access an HTTP URL like http://www.site.ext/shop/category/, it redirects to the homepage of the shop, i.e., https://www.site.ext/shop/.
Understanding the Issue The problem lies in how Magento handles base URLs and rewrites. Let’s break down what’s happening:
- Base URL Configuration: You’ve configured your unsecure base URL as an HTTPS version.
- Rewrite Rules: Magento uses mod_rewrite rules to handle clean URLs. These rules are defined in the
.htaccessfile you provided.
The challenge is that the default Magento rewrite rules are designed for the root directory, not subfolders like /shop/. When a non-existing page (like category) is requested over HTTP, it doesn’t have the correct rewrite rule to map back to the specific HTTPS version of the category page. Instead, it falls back to the base URL rewrite, which redirects to the shop homepage.
The Solution
Step 1: Update Your Base URLs Ensure your base URLs are configured correctly in Magento’s configuration settings:
- Secure Base URL:
https://www.site.ext/shop/ - Unsecure Base URL:
http://www.site.ext/shop/
Step 2: Modify the .htaccess File
Open your /shop/.htaccess file and make the following changes:
-
Update RewriteBase: Change this line to match your actual shop subfolder path:
RewriteBase /shop/ -
Add Custom Rewrite Rules for Your Categories Add these lines just above the
RewriteRule .* index.php [L]line:# Redirect specific HTTP category URLs to HTTPS RewriteCond %{REQUEST_URI} ^/shop/category/([^?]*) [NC] RewriteRule .* https://%{HTTP_HOST}/shop/category/%1?%{QUERY_STRING} [R=301,L] # If the above rule didn't match, fall back to Magento's default rewrite RewriteRule .* index.php [L]
Step 3: Clear Cache After making these changes, flush your Magento cache from the admin panel (System > Cache Management).
Conclusion
The key to solving your issue is understanding how Magento’s base URL configuration and rewrite rules interact. By updating your .htaccess file with specific rewrite rules for your categories and ensuring your base URLs are configured correctly, you should now be able to access all your /shop/ pages via HTTPS.
Remember, this solution assumes you’re using Magento 1.9.1 on a server that supports mod_rewrite. If you encounter any further issues or need more detailed assistance, feel free to explore our Magento Development Services or reach out to us directly.
Happy coding!