www.webdeveloper.com
Results 1 to 2 of 2

Thread: htaccess redirect whole site to https

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    133

    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?


    Code:
    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
    Posts
    19
    RegEx is not (and never will be) my strong point but maybe this holds the answer:

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

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

    Hope it helps
    Cheers
    Dal

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



Recent Articles