Bilal Sheikh
Bilal Sheikh

Reputation: 13

How to redirect all non-www to www and SSL Url in Opencart journal theme?

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 !

Upvotes: 0

Views: 634

Answers (1)

ntzz
ntzz

Reputation: 183

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]

Upvotes: 2

Related Questions