<p>Update 12/06/2018:</p>

<p>Tested now succesfully following version on my server</p>

<pre><code># Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect http to https
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# redirect /bla/ to /bla
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
</code></pre>

CC BY-SA 4.0
2018-12-05T23:16:29.173Z
Tnx, the first piece of code gives a redirect error, after the update piece gives an infinite loop. The test website https://htaccess.madewithlove.be/ with the first piece of code after "Try this" gives the following; OK
-https://www.testwebsite.nl/test/ ok (trailing slash) -http://www.testwebsite.nl/test/ ok www and trailing slash removed NOT OK
-http://www.testwebsite.nl/test (returns https://%1/test )
-all the above urls without www (returns https://%1/test ) In case of without www it must also delete the trailing slash en if http then https. without www redirects the above failing to https
Eugene
CC BY-SA 4.0
2018-12-06T14:38:00.770Z
ok, i tested now on my server and found a working version. i update my previous answer.
phaetons
CC BY-SA 4.0
2018-12-08T15:33:27.340Z
Perfect !! Can i buy you a beer ?

I added the default craftcms piece at last. Maybe the second !-d can be deleted now because it's now by the entry blah/ to blah.

Will you place this piece under your solotion (with or without the 2nd sentence?).
I think this is a perfect CraftCMS solution for apache.



# 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]
Eugene
CC BY-SA 4.0
2018-12-10T10:47:48.747Z
Keep the second !-d, because the first relates only to the RewriteRules before the next condition block. As soon as a new RewriteCond line is stated only the following Rules apply to them. By the way, the !-d conditions apply if the uri is not a real directory, so they only affect "virtual" paths.
phaetons
CC BY-SA 4.0
2018-12-05T13:23:55.147Z
2018-12-06T14:36:36.853Z
2018-12-06T14:36:36.853Z
phaetons
<p>I can't manage to combine all above options. Tested with several options and examples only the most examples focusses only on on problem.</p>

<p>The example of .htaccess below is okay but i cannot manage to add the trailing slash combining with www and the http.</p>

<p>Testing with: <a href="https://htaccess.madewithlove.be/" rel="nofollow noreferrer">https://htaccess.madewithlove.be/</a></p>

<p>SEO company want's to get rid of trailing slash. I see that most of CraftCMS installs responds to slash AND non slash. </p>

<p>See : craftcms website pricing and pricing/ </p>

<p>are also both okay....thats also not ideal while you can introduce duplicate pages for google.</p>

<p>Recap:</p>

<p><a href="http://www.domainname.nl" rel="nofollow noreferrer">http://www.domainname.nl</a>  -> <a href="https://domainname.nl" rel="nofollow noreferrer">https://domainname.nl</a>
<a href="http://www.domainname.nl/products/" rel="nofollow noreferrer">http://www.domainname.nl/products/</a> -> <a href="https://domainname.nl/products" rel="nofollow noreferrer">https://domainname.nl/products</a> (without trailing slash)</p>

<p><a href="https://domainname.nl/products/" rel="nofollow noreferrer">https://domainname.nl/products/</a>      <a href="https://domainname.nl/products" rel="nofollow noreferrer">https://domainname.nl/products</a> (without trailing slash)</p>

<p>
    RewriteEngine On</p>

<pre><code># Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect http to https
RewriteCond %{HTTPS} !on

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

<htaccess>
Combine .htaccess. ( http to https AND www to non www AND remove trailing slash ) extending normal craftcms .htaccess
# Combine .htaccess. ( http to https AND www to non www AND remove trailing slash ) extending normal craftcms .htaccess

(Asked by: username_0 on 2018-12-05)

I can't manage to combine all above options. Tested with several options and examples only the most examples focusses only on on problem.
The example of .htaccess below is okay but i cannot manage to add the trailing slash combining with www and the http.
Testing with: https://htaccess.madewithlove.be/
SEO company want's to get rid of trailing slash. I see that most of CraftCMS installs responds to slash AND non slash. 
See : craftcms website pricing and pricing/ 
are also both okay....thats also not ideal while you can introduce duplicate pages for google.
Recap:
http://www.domainname.nl  -> https://domainname.nl
http://www.domainname.nl/products/ -> https://domainname.nl/products (without trailing slash)
https://domainname.nl/products/ https://domainname.nl/products (without trailing slash)

    RewriteEngine On
# Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect http to https
RewriteCond %{HTTPS} !on

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

**Tags:** htaccess

---

## 1 answers

### Answer by username_1 on 2018-12-05. Score: 2

Update 12/06/2018:
Tested now succesfully following version on my server
# Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Redirect http to https
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# redirect /bla/ to /bla
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

> **Comments:**
> **username_0**: Tnx, the first piece of code gives a redirect error, after the update piece gives an infinite loop. The test website https://htaccess.madewithlove.be/ with the first piece of code after "Try this" gives the following; OK -https://www.testwebsite.nl/test/ ok (trailing slash) -http://www.testwebsite.nl/test/ ok www and trailing slash removed NOT OK -http://www.testwebsite.nl/test (returns https://%1/test ) -all the above urls without www (returns https://%1/test ) In case of without www it must also delete the trailing slash en if http then https. without www redirects the above failing to https  
> **username_1**: ok, i tested now on my server and found a working version. i update my previous answer.  
> **username_0**: Perfect !! Can i buy you a beer ?  I added the default craftcms piece at last. Maybe the second !-d can be deleted now because it's now by the entry blah/ to blah.  Will you place this piece under your solotion (with or without the 2nd sentence?). I think this is a perfect CraftCMS solution for apache.    # 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]  
> **username_1**: Keep the second !-d, because the first relates only to the RewriteRules before the next condition block. As soon as a new RewriteCond line is stated only the following Rules apply to them. By the way, the !-d conditions apply if the uri is not a real directory, so they only affect "virtual" paths.  

---

