1

Using OpenCart how would I use a 301 redirect to add www. to the domain

.htaccess content:

#Options +FollowSymlinks

<IfModule mod_rewrite.c>
RewriteEngine On

#OPENCART REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
#OPENCART REWRITES END

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www\.mysite\.com/$1 [R=301,L]
</IfModule>

Note that 302 redirects are working

Jay Gilford
  • 15,141
  • 5
  • 37
  • 56
Granit
  • 931
  • 3
  • 12
  • 22

3 Answers3

2

I think all that you are wanting to do is this inside of your Apache config file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] 
meme
  • 11,861
  • 2
  • 19
  • 20
0

I use like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.net
RewriteRule ^(.*)$ http://www.mysite.net/$1 [R=permanent,L]
msmafra
  • 1,704
  • 3
  • 21
  • 34
0

Try this code. I am keeping this as standard for non-www to www and force https both. No further change required.

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,NE]