0

I am using the below script to redirect traffic to https. It work fine if I just type domain.com in the address bar but if I type www.domain.com it doesn't get redirected. How do I make it redirect both with and without www?

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Jan
  • 27
  • 1
  • 6
  • 1
    The issue you get is exactly what the second line does – guido May 31 '14 at 00:26
  • I tried to get rid of the second line liek above. It works in safari but in firefox it gets The page isn't redirecting properly message – Jan May 31 '14 at 00:40
  • Maybe duplicate: http://stackoverflow.com/questions/9945655/apache-redirect-http-to-https-and-www-to-non-www – bloodyKnuckles May 31 '14 at 01:16

1 Answers1

0

Try this:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

  • In case you wish to force HTTPS for a particular folder you can use:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} somefolder

RewriteRule ^(.*)$ https://www.yourdomain.com/somefolder/$1 [R,L]

Thanks

Ayman Al-Shorman
  • 190
  • 1
  • 2
  • 18