Forum Moderators: phranque
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#canonical urls
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#trailing slashes
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !\.htm$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.shtml$
#sitemap
RewriteCond %{REQUEST_URI} !\.xml$
#RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) $1/ [R=301,L]
#RewriteRule ^(.*)([^/])$ https://%{HTTP_HOST}/$1$2/ [L,R=301]
#double trailing slashes
#RewriteCond %{REQUEST_URI} ^([^/]+/)([^/]+/)/$
#RewriteCond %{REQUEST_URI} !\.php$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteCond %{REQUEST_URI} !\.htm$
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) $1/ [R=301,L]
</IfModule> <IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#trailing slashes
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !\.htm$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.shtml$
#sitemap
RewriteCond %{REQUEST_URI} !\.xml$
#RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) $1/ [R=301,L]
#RewriteRule ^(.*)([^/])$ https://%{HTTP_HOST}/$1$2/ [L,R=301]
#double trailing slashes
#RewriteCond %{REQUEST_URI} ^([^/]+/)([^/]+/)/$
#RewriteCond %{REQUEST_URI} !\.php$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteCond %{REQUEST_URI} !\.htm$
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) $1/ [R=301,L]
</IfModule> [edited by: engine at 9:46 am (utc) on Apr 21, 2016]
[edit reason] please use example.com [/edit]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.example.com/$1 [R=301,L]