Home .htcaccess redirect no www to www with SSL
Reply: 0

.htcaccess redirect no www to www with SSL

user6843
1#
user6843 Published in September 19, 2018, 9:52 am

For a long time we have had our site running without www in front, but we have recently been forced to make a change.

We recently changed from domainhere.com to www.domainhere.com. We already had a redirect from http to https, but need to change the redirect from https://domainhere.com to https://www.domainhere.com.

We used this code. How do we make it still redirect to HTTPS but with www in front?

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.skarpeknive.dk/$1 [R,L]

We found this on Stackoverflow, but it doesn't seem to work. The site bugs on domainhere.com then

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

share|improve this question
  • Your rule looks like it should work. Did you clear your browser cache before testing the rule? – starkeen Apr 2 at 16:05
  • Hello. I did. I would say it should work too. Maybe it just takes a while for my computer to adjust. Coud you test it? The site is skarpeknive.dk – eMikkelsen Apr 2 at 19:18

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314144 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO