Drupal htaccess

Additional .htaccess settings for Drupal

Here are some extra .htaccess commands to add to the standard Drupal setup

Allow access for SSL LetsEncrypt.com

If you are using LetsEncrypt, the default security stops access for folders starting with a period

RewriteCond %{REQUEST_URI} "/.well-known/"
RewriteRule (.*) $1 [L]

Force SSL

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect to non-WWW

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

Redirect images folder to default images

This means that you can use shortened URI of /images/here.gif instead of the full path into /sites/default/files/images/here.gif

RewriteRule ^images/(.*\.(gif|png|jpe?g))$ sites/default/files/images/$1 [QSA,NC]

Leave a Reply