I have an opencart SSL (https) ecommerce site with the following issue. When I search on google for my site it defaults to https://ricambimoto.uk which causes some of the font awesome icons not to show up on first loading the browser with the cache cleared. If I refresh the browser page it changes the URL to https://www.ricambimoto.uk and all is well. My htaccess file in the ReWrite section is as follows:
RewriteBase /
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) 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]
Is there a glaring error here as I can't see what could be causing it? I need to force the URL to add the www element every time.
I should add that I have amended the root and admin config files as follows as well
root config.php
// HTTP
define('HTTP_SERVER', 'https://www.ricambimoto.uk/');
// HTTPS
define('HTTPS_SERVER', 'https://www.ricambimoto.uk/');
admin config.php
// HTTP
define('HTTP_SERVER', 'https://www.ricambimoto.uk/admin/');
define('HTTP_CATALOG', 'https://www.ricambimoto.uk/');
// HTTPS
define('HTTPS_SERVER', 'https://www.ricambimoto.uk/admin/');
define('HTTPS_CATALOG', 'https://www.ricambimoto.uk/');
CodePudding user response:
Try to force non www
. Add to your .htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
CodePudding user response:
RewriteCond %{HTTPS_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
It should be HTTP_HOST
in the first line (RewriteCond
directive), not HTTPS_HOST
(which doesn't exist).
However, as written, this should have generated an endless redirect-loop? And you have inconsistencies between a route
and _route_
URL parameter in your rules. And the URLs throughout your site use the form /index.php?route=<page>
which doesn't require .htaccess
. This makes me wonder whether your .htaccess
file is actually doing anything?