Apache .htaccess and mod_rewrite on Gentoo Linux
Enable mod_rewrite
# Add 'rewrite' to APACHE2_MODULES in /etc/conf.d/apache2
rc-service apache2 restart
Allow overrides in virtual host
<Directory /var/www/example.com/html>
AllowOverride All
Require all granted
</Directory>
Common .htaccess recipes
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Remove www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
CMS front controller
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Block dotfiles
<FilesMatch "^\.">
Require all denied
</FilesMatch>
Gzip compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>