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]

New contributor
Eugene is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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]
  • Tnx, the first piece of code gives a redirect error, after the update piece gives an infinite loop. The test website htaccess.madewithlove.be with the first piece of code after "Try this" gives the following; OK -testwebsite.nl/test ok (trailing slash) -testwebsite.nl/test ok www and trailing slash removed NOT OK -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 Dec 5 at 23:16
  • ok, i tested now on my server and found a working version. i update my previous answer. – phaetons Dec 6 at 14:38
  • 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 Dec 8 at 15:33
  • 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 yesterday

Your Answer

Eugene is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.