Page 1 of 1

https issue redirect

Posted: Tue Dec 05, 2017 11:44 pm
by ianhaney
Hi

I have a SSL installed in my opencart 2.0.3.1 store and it works on https://www.it-doneright.co.uk/shop/ but if I take out the https:// part so it just leaves the www.it-doneright.co.uk/shop/, it redirects to https://www.it-doneright.co.uk

I don't get it, the htaccess file inside the shop folder is below

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>

# SEO URL Settings

RewriteEngine On

# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

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

Rewritebase /shop/

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]

RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]

RewriteRule ^system/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]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.

### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:

# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try

# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields

# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields

# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations

# php_admin_value open_basedir none

Can anyone help please as don't know to solve it, I want it so that if it's www.it-doneright.co.uk/shop/ that it changes to https://www.it-doneright.co.uk/shop/

Thank you in advance

Re: https issue redirect

Posted: Wed Dec 06, 2017 12:13 am
by ianhaney
It seems it's working now but now if I take out the https:// part and leave just www.it-doneright.co.uk/shop, is there a way to make it appear like https://www.it-doneright.co.uk/shop/

Re: https issue redirect

Posted: Wed Dec 06, 2017 1:38 pm
by webdev1
Did you manage to sort Undefined index: token error messages on admin problem out?

Re: https issue redirect

Posted: Wed Dec 06, 2017 5:50 pm
by ianhaney
Hi

I didn't get to sort that issue out, I am not sure how to solve that issue

Re: https issue redirect

Posted: Wed Dec 06, 2017 9:00 pm
by kestas
Hi,

to force https you can try add this piece of the code to your .htaccess file

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Cheers

Re: https issue redirect

Posted: Wed Dec 06, 2017 10:38 pm
by MrPhil
Even better, take care of forcing https and www. (or no www.) in the same redirect:

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS}  !on  [OR]
RewriteCond %{HTTP_HOST}  !^www\.  [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
Adjust accordingly if you don't want www. I prefer to not use HTTP_HOST in the rewrite rule, because if it came in as mydomain.com, that's what will be used (hard code the domain name). Combining the https force and the www force is advantageous because it's only one 301 address change sent back to the browser, rather than two round trips.

When you say, "drop the https://", I take it you're talking about the browser address bar? Most browsers will automatically add "http://" to the URL. Why your .htaccess didn't rewrite this with the REQUEST_URI, I don't know. Try it with $1 and see if it works then.

Re: https issue redirect

Posted: Wed Dec 06, 2017 11:01 pm
by ianhaney
Hi

I tried the following but when I drop the https:// part from the address bar, it just goes to the main domain name https://www,it-doneright.co.uk where as I would like to stay within the shop folder, I put the following just after RewriteBase /shop/. Is that the right place?

RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.it-doneright.co.uk/$1 [R=301,L]

should I add /shop/ just before the $ sign?

UPDATE: Sorry also after doing the above the admin side is coming up with a 404 page because it's redirecting to the root domain

Re: https issue redirect

Posted: Wed Dec 06, 2017 11:21 pm
by MrPhil
ianhaney wrote:
Wed Dec 06, 2017 11:01 pm
Hi

I tried the following but when I drop the https:// part from the address bar, it just goes to the main domain name https://www,it-doneright.co.uk where as I would like to stay within the shop folder, I put the following just after RewriteBase /shop/. Is that the right place?

RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.it-doneright.co.uk/$1 [R=301,L]

should I add /shop/ just before the $ sign?

UPDATE: Sorry also after doing the above the admin side is coming up with a 404 page because it's redirecting to the root domain
What are you trying to accomplish here? In addition to forcing https and www, are you also looking to silently jump a visitor entering at http(s)://(www.)it-doneright.co.uk to /shop/? If so, below the code given above, add

Code: Select all

RewriteCond  %{REQUEST_URI}  !^/shop  [NC]
RewriteRule  ^(.*)$  /shop/$1
You don't want to hard code /shop/ into the https/www rewrite, in case the original request included /shop.

If you need RewriteBase /shop/ for other purposes, put it after this code.

Re: https issue redirect

Posted: Wed Dec 06, 2017 11:46 pm
by ianhaney
It's ok I will leave it as it is, I just wanted it that if in the address bar I remove the https:// part that it automatically adds it back in again after pressing enter but the way it is now is ok

Re: https issue redirect

Posted: Thu Dec 07, 2017 10:11 pm
by MrPhil
Just to clarify, if you drop the https:// part, your browser will add http:// in for you. Then, your server's .htaccess bounces it back to your browser with a 301 redirect to use https instead of http. To minimize the number of redirect round trips, it's best to combine as many 301 redirects as you can into one go (e.g., http->https and add www together).

Re: https issue redirect

Posted: Thu Dec 28, 2017 10:31 pm
by ianhaney
Hi

Sorry for just replying, thank you for the info and help etc. appreciate it