Page 1 of 1

https:// to https://www per htaccess

Posted: Wed Jan 17, 2018 12:00 am
by MAD King
Hello,

I would need some help. I am not able to figure it out.
I have SSL installed and it is always pointing to https, but it keeps it https://domain.com when entered and I would like to refer it to https://www.domain.com
My htaccess looks like this:

Code: Select all

Options +SymLinksIfOwnerMatch

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|.twig|\.ini|\.log|(?<!robots)\.txt))">
 Require all denied
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# 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/

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]

### 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
OC Version 2.3.0.2

Thank you

Re: https:// to https://www per htaccess

Posted: Wed Jan 17, 2018 8:18 am
by IP_CAM
Try this:
AFTER:

Code: Select all

RewriteBase /
EITHER, if http:// used:

Code: Select all

#Force (http host) non www to www (optional)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
OR, if https:// used:

Code: Select all

#Force (https host) non www to www (optional)
RewriteCond %{HTTPS} on
RewriteCond %{HTTPS_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTPS_HOST}/$1 [R=301,L]
Ernie

Re: https:// to https://www per htaccess

Posted: Wed Jan 17, 2018 8:25 am
by MAD King
Hello Ernie,

thank you. When I add your https code and enter https://domain.com I get just https://www. and not the expected https://www.domain.com

Re: https:// to https://www per htaccess

Posted: Wed Jan 17, 2018 8:27 am
by IP_CAM
then, change this:

Code: Select all

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

Code: Select all

RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
and try again. I never used https yet, so I cannot test it.
Ernie

Re: https:// to https://www per htaccess

Posted: Wed Jan 17, 2018 8:39 am
by MAD King
Weird. Now I get a https://www.www.domain.com
when I use

Code: Select all

#Force (https host) non www to www (optional)
RewriteCond %{HTTPS_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Re: https:// to https://www per htaccess

Posted: Sun May 19, 2019 6:32 pm
by michael2820
not a good idea to suggest something, when you are not SURE about it

Re: https:// to https://www per htaccess

Posted: Sun Jun 23, 2019 5:11 am
by groteschatten
In my htaccess I put:

Code: Select all

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301] 
Works perfect for me, let me know if it helps.

Re: https:// to https://www per htaccess

Posted: Mon Jun 24, 2019 9:38 pm
by EvolveWebHosting
Update both of your config.php files to use www in the HTTP and HTTPS sections of the file as well.