Results 1 to 2 of 2

Thread: htaccess redirect whole site to https

  1. #1
    Join Date
    Dec 2008

    htaccess redirect whole site to https

    I am using the below code in htaccess 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 %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

  2. #2
    Join Date
    Feb 2008
    RegEx is not (and never will be) my strong point but maybe this holds the answer:

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

    The above code ensures that the website only ever uses http://www.

    Hope it helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center