0

I'm trying to redirect all https://example.com to https://www.example.com and I can't find anything that works. I want to do this as I think it will look better and it will make logging in easier as you currently have to login at both domains as they're treated as being different. I added this .htaccess file in case this is what I've got wrong?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
willmahoney
  • 371
  • 1
  • 2
  • 9
  • Does this answer your question? [apache redirect from non www to www](https://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www) – AD7six Sep 06 '21 at 10:22

1 Answers1

2

Try this:

# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Rateb Habbab
  • 1,739
  • 8
  • 13