No announcement yet.

htaccess - Force https://www for root and all subfolders

  • Filter
  • Time
  • Show
Clear All
new posts

  • htaccess - Force https://www for root and all subfolders

    I am trying to create an htaccess rule to do the following...

    Force all http:// and http://www. requests to https://www. - including all subfolders.

    So redirects to

    and redirects to

    I am currently using...

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{HTTPS} !=on
     RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    But that does not add the www. and subfolder URLs remain at http://

    Been searching Google for over an hour looking for something that works, but I have found nothing that works!

    Help appreciated.

  • #2
    Can you try this

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$$1 [R,L]


    • #3
      Hmmm, very odd. That doesn't do anything more than what my first block of code does.

      - It does not redirect subfolder URLs to httpS:

      - It does redirect to httpS:// but it does not add www.

      - In fact, it removes the www. for every URL regardless if root or subfolder

      I'm testing on FF and chrome with same results.


      • #4
        clivejo, thanks for your help. I ended up having to install a plugin to get the job done.
        I knew this was an option, but I try only to install plugins as a last resort. This is one of those times. :/


        • #5
          Oh, you didn't mention you are using Wordpress!! Wordpress uses the database and PHP to modify the URL and you also need to change it in you Dashboard.

          Settings > General and change your WordPress Address (URL) and Site Address (URL) to use https


          • #6
            Sorry about that. I didn't think it mattered that it was wordpress.

            Yes, if you want www. in your URL, that has to be changed in WP setting/General.

            Unfortunately, that doesn't solve the problem of subfolders not redirecting to httpS. So I gave up and installed the plugin and that solved it. Now every non-SSL url that it accessed redirects to https://www.