Enabling mod_rewrite lets Apache rewrite incoming requests before content is served, which is how clean URLs, canonical redirects, and front-controller routing actually work. When the module is missing or disabled, RewriteRule and RewriteCond directives are ignored and applications commonly fall back to broken routes, unexpected 404s, or duplicate URL variants.
On Debian and Ubuntu, a2enmod enables packaged modules by creating the active symlinks under /etc/apache2/mods-enabled, and apache2ctl can confirm whether rewrite_module is loaded. If rewrite rules live in .htaccess instead of the main site configuration, the matching Directory block also has to permit FileInfo overrides or Apache will read the file without honoring the rewrite directives inside it.
The steps below assume a packaged Apache install on Ubuntu or Debian with the apache2 service name. Apache documentation still recommends keeping rewrite rules in the main server configuration when possible because .htaccess adds per-request filesystem lookups, but if you need per-directory control you must also keep Options FollowSymLinks enabled for that directory and restart Apache after enabling the module.
$ sudo apache2ctl -S VirtualHost configuration: *:80 host.example.net (/etc/apache2/sites-enabled/000-default.conf:1) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" ##### snipped #####
The file and line number next to the host usually point to the fastest path back to the correct VirtualHost.
$ sudo a2query -m rewrite No module matches rewrite
If the query already reports rewrite (enabled by site administrator), keep the module enabled and continue with the override, test, and reload steps.
$ sudo a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: service apache2 restart
a2enmod enables the packaged module by creating the active symlinks under /etc/apache2/mods-enabled.
$ sudoedit /etc/apache2/sites-available/000-default.conf
Edit the source file in /sites-available/ rather than the symlink in /sites-enabled/ so future a2ensite or a2dissite changes stay consistent.
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride FileInfo
Require all granted
</Directory>
Use AllowOverride FileInfo only when the rewrite rules must live in .htaccess. If you can keep the rules directly in the VirtualHost, do that instead and skip distributed overrides.
$ sudo apache2ctl configtest AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.0.2.10. Set the 'ServerName' directive globally to suppress this message Syntax OK
The AH00558 line is a hostname warning, not a syntax failure.
Related: How to test Apache configuration
$ sudo systemctl restart apache2
After the module is enabled, later rewrite-rule edits can usually be applied with sudo systemctl reload apache2 instead of a full restart.
$ sudo apache2ctl -M | grep rewrite_module rewrite_module (shared)
$ sudo mkdir -p /var/www/html/rewrite-test
$ sudo tee /var/www/html/rewrite-test/.htaccess >/dev/null <<'EOF' RewriteEngine On RewriteRule ^$ / [R=302,L] EOF
RewriteEngine On is required in each VirtualHost, Directory, or .htaccess context where you want the rules in that context to run.
$ curl -sI http://127.0.0.1/rewrite-test/ HTTP/1.1 302 Found Date: Thu, 09 Apr 2026 04:07:10 GMT Server: Apache/2.4.58 (Ubuntu) Location: http://127.0.0.1/ Content-Type: text/html; charset=iso-8859-1
If the site only responds on a named virtual host, use that hostname or pass a matching Host header instead of 127.0.0.1.
$ sudo rm -rf /var/www/html/rewrite-test
Check the path carefully before running a recursive remove so you do not delete real application content.