0

The problems are like

  1. When I use http://www.example.com : It works fine.
  2. When I use https://www.example.com : It works fine with my www ssl certificate
  3. When I use http://example.com : I lose my styles and icons.
  4. When I use https://example.com : I lose my styles and icons.

Now I want it in these ways :

  1. When I use http://example.com : It should redirect to https://www.example.com
  2. When I use http://www.example.com : It should redirect to https://www.example.com.
  3. When I use only example.com : It should redirect to https://www.example.com

Here is my current .htaccess.txt

# 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=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]

Please direct me how I can achieve what I want and how to fix styles and icons problem. Thanks in Advance !

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • This would be better done at the `httpd-vhosts.conf` level if you can. Configure separate `` directives for the domain with **and** without the *www*, with the "base" `` just having something like `Redirect * https://www.example.com` in it. – CD001 Apr 04 '18 at 10:07
  • Possible duplicate of [htaccess redirect to https://www](https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www) – But those new buttons though.. Apr 07 '18 at 03:40

1 Answers1

2

Check the below code inside htaccess:

RewriteCond %{HTTPS} off
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
user7282
  • 5,106
  • 9
  • 41
  • 72
ntzz
  • 183
  • 4
  • 22