OpenCart 1.5站点SSL启用后.htaccess配置致站点无法加载求助
Hey there,
It sounds like you’re on the right track suspecting that the _route_ RewriteRule is causing conflicts with your HTTPS redirects. OpenCart 1.5’s routing relies heavily on that rule, so placing redirects in the wrong order or using conflicting syntax can easily break your site. Let’s walk through the fix step by step:
First, Double-Check Your config.php Files
Before diving into .htaccess, confirm both your root and admin/ directory config.php files are properly configured for HTTPS (you mentioned you’ve done this, but a quick verification never hurts):
- In root
config.php:define('HTTP_SERVER', 'https://yourdomain.com/'); define('HTTPS_SERVER', 'https://yourdomain.com/'); define('HTTP_IMAGE', 'https://yourdomain.com/image/'); define('HTTPS_IMAGE', 'https://yourdomain.com/image/'); - In
admin/config.php:define('HTTP_SERVER', 'https://yourdomain.com/admin/'); define('HTTPS_SERVER', 'https://yourdomain.com/admin/'); define('HTTP_IMAGE', 'https://yourdomain.com/image/'); define('HTTPS_IMAGE', 'https://yourdomain.com/image/');
Incorrect URLs here can cause silent conflicts with your redirect rules even if the site loads over HTTPS initially.
Correct .htaccess Configuration
The critical fix is to place your HTTPS redirect rule before OpenCart’s core routing rules (including the _route_ one). Here’s the full working .htaccess structure:
RewriteEngine On RewriteBase / # Redirect HTTP to HTTPS (place this FIRST) RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # OpenCart's core routing rules (keep these intact, after the redirect) RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] RewriteRule ^download/(.*) /index.php?route=error/not_found [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Why This Works:
- Redirect Order: The HTTPS redirect runs first, forcing all traffic to HTTPS before OpenCart’s routing logic processes the request. If you had the redirect after the
_route_rule, routing would trigger first, leading to conflicts or infinite loops. - Loop Prevention: The
RewriteCond %{HTTPS} offcondition ensures the redirect only fires for non-HTTPS requests, stopping the server from redirecting itself repeatedly. - Query String Preservation: Adding the
QSA(Query String Append) flag to the_route_rule ensures any existing query parameters are passed through, which is essential for OpenCart’s functionality like search filters or checkout flows.
Post-Configuration Steps:
- Clear your browser cache (301 redirects are cached aggressively—use incognito mode for testing to avoid old cached redirects interfering).
- Test both front-end and admin URLs to confirm no broken links or redirect loops occur.
If issues persist, double-check that your server has SSL properly configured (no certificate errors) and that mod_rewrite is enabled on your Apache server.
内容的提问来源于stack exchange,提问作者Andrew Real

