Post by codywood » Wed Apr 19, 2017 7:08 am

Right now I'm using the following to force a redirect to https.

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

However, it won't redirect the following use if there is no www:

https://domain.com displays an error that the page is not secure.

Anyone help?

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by viethemes » Wed Apr 19, 2017 10:38 pm

Could you provide your site URL so we can take a look at the problem closer?

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by artcore » Thu Apr 20, 2017 1:47 am

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) https://domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteBase /
or direct to www + https

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteBase /
In human words: if not https or if not starts with www direct to https + www retaining the params after the domain. Take notice of the placing; after RewriteEngine On, before RewriteBase

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: I moved on to Laravel ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by TobikSoft » Thu Apr 20, 2017 4:26 pm

Code: Select all

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If "www" ->301 redirect to-> https://...
If not https ->301 redirect to-> https://...

Use the most required FREE extensions:
Quick Registration and Promotional Stickers can increase sales.
Easier for customers - better for you!


User avatar
New member

Posts

Joined
Sun Jan 11, 2015 6:30 am

Post by codywood » Fri Apr 21, 2017 2:54 am

I believe I would use this version:

E

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteBase /

But there is more to consider. For instance, my OpenCart admin uses the following URL template:
https://admin.domain.com

If I were to use the version above then wouldn't it result in pretending 'www' to this admin URL, like this?:
https://www.admin.domain.com

And, how would it affect other store URLs when the store is installed as a subdomain?:
https://store2.domain.com

--Thank you

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by codywood » Mon Apr 24, 2017 5:14 pm

DOES ANYONE HAVE A SOLUTION? Please read the above post.

Using the .htaccess file, I need to redirect all of the following URLs to this URL, https://www.domain.com/:

https://domain.com
http://domain.com
http://www.domain.com
www.domain.com
domain.com

Thank you

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by uksitebuilder » Mon Apr 24, 2017 8:42 pm

Well, the first thing to do is test for SSL

Code: Select all

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule  ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,NE]
Then check for the www. or admin

Code: Select all

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

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by codywood » Wed Apr 26, 2017 5:21 am

You lost me at 'admin'. What do you mean that you check for admin? Are you assuming that the backend of opencart uses admin.domain.com ?

I have not tried this code but will it also forward any URL that does not have the 'S' at the end of HTTPS, or whether it has WWW or not?

Thanks

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by uksitebuilder » Wed Apr 26, 2017 2:19 pm

That was what you stated a couple of posts up

The way htaccess works with rewrites is from the top down until it hits a rule that matches - Then it redirects and goes through htaccess again from top down, rinse and repeat until all rules are satisfied.

So first thing my code does is check for SSL - If SSL is off it simply redirects the URL entered to SSL

Next pass, it check if the url begins with either www or admin, if it doesn't it will redirect to the www.domain url

If you add subdomains in the future, you will need to amend the second lot of code I posted to add those subdomains, similar to how the www and admin have been added with an [OR] flag

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by codywood » Thu Apr 27, 2017 2:18 pm

That kind of make sense. I'll try it tomorrow. Thanks for your help....

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by codywood » Tue May 02, 2017 7:04 am

If you are still following, as a reminder, I was using the following:

Code: Select all

# Force https everywhere
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I was give, as one possible solution, this code:

Code: Select all

ewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule  ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,NE]

RewriteCond %{HTTP_HOST} !^www\. [NC]  [OR]
RewriteCond %{HTTP_HOST} !^admin\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,NE]
It did not work, as it was. I ended up combining what I had with what I was given. The end result is this:

Code: Select all

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

RewriteCond %{HTTP_HOST} !^www\. [NC]  [OR]
RewriteCond %{HTTP_HOST} !^admin\. [NC] [OR]
RewriteCond %{HTTP_HOST} !^store2\. [NC] [OR]
RewriteCond %{HTTP_HOST} !^inno\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,NE]
I had to remove this:

Code: Select all

RewriteRule  ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,NE]
Can any one explain why the original code given did not work but what I did was successful?

UPDATE.....

I discovered that the change I made did not work. When I use the code as it was given to me in this form I cannot access the admin side which is at admin.domain.com/admin.

i suspect what I said I removed needs to be changed in some way, but I don't know how. CAN ANYONE HELP?

Code: Select all

RewriteRule  ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,NE]

New member

Posts

Joined
Mon Sep 15, 2014 10:42 am

Post by CrucialPiXel » Sun Jul 29, 2018 3:32 am

I could not get any https redirect to work as all of them would cause a too many redirects issue. I finally got it to work when using this line "RewriteCond %{HTTP:X-Forwarded-Proto} !https " (without quotes) along with a redirect rule I listed below. Just wanted to pass it along for anyone else who spent weeks looking for a solution like me. I found no issues after putting in it place, it even works for the /admin login as well. It even redirects www.

This is part of my .htaccess file, notice the last two lines. Just add those 2 lines to your .htaccess file in the same location.
RewriteBase /
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]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Newbie

Posts

Joined
Sun Jul 29, 2018 3:24 am

Post by straightlight » Sun Jul 29, 2018 7:12 pm

RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
Ensure this line doesn't stick in if you did moved your storage folder outside your public_html folder.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 7 guests