<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>

CC BY-SA 3.0
2018-01-11T18:06:36.163Z
2018-01-11T18:30:04.370Z
2018-01-11T18:30:04.370Z
Robin Schambach
<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>

<htaccess><ssl>
How do I force www in URL along with the Patrol plugin to force https
# 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

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.

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.

    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]

Action application/x-httpd-php70 /cgi-sys/php70-fcgi-starter.fcgi
AddType application/x-httpd-php70 .php .php70


---

