0

I use this simple code to redirect non-www http to www https

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It succesfully redirect http://example.com to https://www.example.com. But when I tried to access http://example.com/somefolder it did not redirected. Am I missing some syntax here? or something else?

Kukuh Indrayana
  • 204
  • 3
  • 9

1 Answers1

0

Change %{REQUEST_URI} to /$1 ( first match in rule .* )

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [L,R=301]

or modify last rule pattern:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
JarekBaran
  • 1,311
  • 2
  • 7
  • 12