Need to migrate your e-mails to a new server? Free and paid versions of our online tool available.
Hero Image

Apache .htaccess and mod_rewrite on AlmaLinux 9

Apache .htaccess and mod_rewrite on AlmaLinux 9

Enable mod_rewrite

# mod_rewrite is loaded by default in /etc/httpd/conf.modules.d/00-base.conf

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>