Combining rewrites for non-www/ssl/trailing slash with upper->lowercase in .htaccess Combining rewrites for non-www/ssl/trailing slash with upper->lowercase in .htaccess apache apache

Combining rewrites for non-www/ssl/trailing slash with upper->lowercase in .htaccess


Have it like this in your site root .htaccess:

RewriteEngine On# add www, httpsRewriteCond %{HTTPS} !on [OR]RewriteCond %{HTTP_HOST} !^www\. [NC]RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]RewriteRule ^ https://www.%1%{REQUEST_URI}  [R=301,L,NE]# add a trailing slash is query string is not presentRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^[^.]+?[^/]$ %{REQUEST_URI}/ [L,R=301,NE]# convert URI to lowercase# This requires Apache 2.4RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond expr "tolower(%{REQUEST_URI}) =~ m#(.+)#"RewriteRule [A-Z] %1 [L,NE,R=301]