HT Access Tweaks

Brief summary of trivial HT Access Tweaks.

Conditions

Conditions works like a Perl regular expression without delimiter, describing the condition required for string. An exclamation mark before an expression means not.

Flags are optional. You can use them to manipulate the value of RewriteCond. Multiple flags are separated with a comma.

RewriteEngine

RewriteLogLevel

The default value of RewriteLogLevel is zero, effectively disabling all logging. A value of one logs important stuff only. Values greater than two are more verbose but may stress the server.

RewriteRule

RewriteRule defines the actual redirect and may occur multiple times. Ordering is important because every redirect is executed in exactly the order it occurs.

Parameters are given in the form of source and target where source is a Perl compatible regular expression without delimiter indicating the redirect source and target is the redirect target if the condition is true. RewriteRule may have additional options, which are executed if the condition is true.

Enable Gzip Compression

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE
                        text/html
                        text/plain
                        text/xml
                        text/css
                        text/javascript
                        image/vnd.microsoft.icon
</IfModule>
      

Fix Trailing Slash

DirectorySlash On
      

Redirect to HTTPS

RewriteCond %{HTTP_HOST} ^!example.com
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
      

Redirect to non-www

RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*) http://example.com/$1 [R=301,L]