Post by kevins93 » Tue Jul 05, 2016 10:14 pm

Hi!

Google like it when you always use https. So, I put the following code in my .htaccess:

Code: Select all

RewriteBase /
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]

RewriteEngine On
rewritecond %{http_host} ^www.WEBSITE.nl
rewriteRule ^(.*) http://WEBSITE.nl/$1 [R=301,L] 

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
It works fine, everyone who use http:// or http://www. will get the https:// page.
The links on the website works also fine.
But..

Visitors who are going directly to any page will get a code in the URL. The visitors from Google are getting the same.
Example: http://website.nl/page goes to https://website.nl/index.php?_route_=page.

It works, but I don't think Google like this..
Before I use the last part of the code I didn’t have this problem. The VQmod codes I know doesn’t work :(
Any ideas? Thanks!

Newbie

Posts

Joined
Fri Mar 28, 2014 3:16 am

Post by labeshops » Tue Jul 05, 2016 10:44 pm

I just did this over the weekend and after a lot of trial and error, what worked for me is:

Code: Select all

RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} 80 

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This first redirects non www to www THEN rewrites http: to https:

Trying to do it in 1 step kept breaking things.

I did this for v2.2 but it should work for all versions I think

Running Opencart v3.0.3.9 with multi-stores and the default template from https://www.labeshops.com which has links to all my stores.


User avatar
Expert Member

Posts

Joined
Thu Aug 04, 2011 4:41 am
Location - Florida, USA

Post by kevins93 » Tue Jul 05, 2016 11:30 pm

Thanks! It looks like it works well :)
Just chanced the code a bit because I like the https:// more than the https://www. :joker:

Hope Google likes this way, thanks a lot!

Code: Select all

RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} 80 

rewritecond %{http_host} ^www.WEBSITE.COM
rewriteRule ^(.*) http://WEBSITE.com/$1 [R=301,L]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Newbie

Posts

Joined
Fri Mar 28, 2014 3:16 am
Who is online

Users browsing this forum: No registered users and 109 guests