Answers.Body: <p>This is how our default <code>.htaccess</code> with https redirect and forced <code>www.</code> for all our projects looks like. So if you have the url <code>example.com</code> you'll get redirected to <code>https://www.example.com</code>.</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
      RewriteRule (.+) index.php?p=$1 [QSA,L]
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
      RewriteCond %{HTTPS} !=on
      RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  &lt;/IfModule&gt;
  Action application/x-httpd-php70 /cgi-sys/php70-fcgi-starter.fcgi
  AddType application/x-httpd-php70 .php .php70
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-11T18:06:36.163Z
Answers.LastActivityDate: 2018-01-11T18:30:04.370Z
Answers.LastEditDate: 2018-01-11T18:30:04.370Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm using the Patrol plugin to force https in the domain, but I also need to force www into the URL. When I do that with some htaccess rewrite rules I found online I get an error when I try to load the site that there's too many redirects happening.</p>
  
  <p>This is my htaccess code</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  </code></pre>
  
  <p></p>
  
  <p>And this was the code to force WWW that I was trying unsuccessfully to use that resulted in the "too many redirects" error.</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  #force www in URL
  RewriteCond %{HTTPS_HOST} !^www\.adacore\.com
  RewriteRule (.*) https://www.adacore.com/$1 [R=301,L]
  
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  </code></pre>
  
  <p></p>
  
  <p>I'm not sure how or if the Patrol plugin (<a href="https://github.com/selvinortiz/craft.patrol" rel="nofollow noreferrer">https://github.com/selvinortiz/craft.patrol</a>) factors into the htaccess file to be honest. Any idea what I'm doing wrong?</p>
  
Tags: <htaccess><ssl>
Title: How do I force www in URL along with the Patrol plugin to force https
ThreadText: # How do I force www in URL along with the Patrol plugin to force https
  
  (Asked by: username_0 on 2018-01-11)
  
  I'm using the Patrol plugin to force https in the domain, but I also need to force www into the URL. When I do that with some htaccess rewrite rules I found online I get an error when I try to load the site that there's too many redirects happening.
  
  This is my htaccess code
  
  ```
  <IfModule mod_rewrite.c>
  RewriteEngine On
  
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  
  ```
  
  And this was the code to force WWW that I was trying unsuccessfully to use that resulted in the "too many redirects" error.
  
  ```
  <IfModule mod_rewrite.c>
  RewriteEngine On
  #force www in URL
  RewriteCond %{HTTPS_HOST} !^www\.adacore\.com
  RewriteRule (.*) https://www.adacore.com/$1 [R=301,L]
  
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # Send would-be 404 requests to Craft
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
  RewriteRule (.+) index.php?p=$1 [QSA,L]
  
  ```
  
  I'm not sure how or if the Patrol plugin (<https://github.com/selvinortiz/craft.patrol>) factors into the htaccess file to be honest. Any idea what I'm doing wrong?
  
  **Tags:** htaccess, ssl
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-11. Score: 2
  
  This is how our default `.htaccess` with https redirect and forced `www.` for all our projects looks like. So if you have the url `example.com` you'll get redirected to `https://www.example.com`.
  
  ```
  <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
      RewriteRule (.+) index.php?p=$1 [QSA,L]
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
      RewriteCond %{HTTPS} !=on
      RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  </IfModule>
  Action application/x-httpd-php70 /cgi-sys/php70-fcgi-starter.fcgi
  AddType application/x-httpd-php70 .php .php70
  
  ```
  
  
  ---
  
  