Redirect my OpenCart site from non-www version to the www version

Avatar
  • Answered
I would like to redirect my OpenCart site from the non-www version to the www version.

Here is what my .htaccess file looks like now:

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

Any help is much appreciated, thanks in advance

ArkenSeal

Avatar
JacobIMH
Hey ArkenSeal, and thanks for the great question. We actually have a guide on force the www version of a domain which in your case would end up looking like this part highlighted in red:
# SEO URL Settings
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
Of course you'll want to replace example.com with your own domain name for it to work properly. Let us know if that does the trick for you, and if you have any other questions at all! - Jacob