Enable Apache’s rewrite engine with sudo a2enmod rewrite, restart Apache with sudo systemctl restart apache2.service, and verify that rewrite_module appears in apache2ctl -M. If rules in .htaccess still do nothing, loading the module is not the missing step: the matching <Directory> block must permit the required overrides, normally with AllowOverride FileInfo.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What enabling mod_rewrite actually changes
mod_rewrite is Apache’s runtime URL-rewriting engine. It can redirect a request, internally map one URL to another resource, add conditions, and apply regular-expression rules. On Ubuntu, Apache modules are managed through the Debian/Ubuntu layout. The a2enmod utility enables a named module by creating the appropriate links in /etc/apache2/mods-enabled; enabling the module does not itself restart the web server or authorize every directory to read .htaccess files.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
There are therefore two separate checks:
- Is the module loaded? The Apache process must load
rewrite_module. - Is rewriting allowed where your rules live? A
.htaccessfile is ignored when its directory usesAllowOverride None(andAllowOverrideList None).
Keeping those checks separate makes most “RewriteRule does nothing” problems straightforward to diagnose.
Before changing Apache, identify the site and document root
Make changes to the virtual host that serves the request, not to an unrelated example site. Confirm that Apache2 is installed and running, then inspect the active virtual-host map and configuration files.
#1 Best Overall
- Check the service and version:
systemctl status apache2.service apache2ctl -vThe status output should show the service running. If it is stopped, start it before testing rewrite behavior:
sudo systemctl start apache2.service - List the virtual hosts Apache selected:
sudo apache2ctl -SThe output identifies each listening address, the default virtual host, and the configuration file and line that define each host.
- Open the configuration file named by that output. Ubuntu commonly stores enabled site links in
/etc/apache2/sites-enabled/, with the corresponding files in/etc/apache2/sites-available/. Find theDocumentRootfor the hostname you are testing. That path is the directory whose<Directory>policy must permit your.htaccessdirectives. - Check whether the requested path is actually inside that document root. A rule in
/var/www/example/.htaccesscannot affect a site whose active document root is/srv/www/other-site.
Do not loosen the filesystem root or every site just to make one application work. Apply the narrowest setting to the directory that serves the application.
Enable and verify the module
1. Enable rewrite
Run:
sudo a2enmod rewrite
If Ubuntu reports that the module is already enabled, that is not an error. Continue with the restart and verification steps; the message only means the module links already exist.
2. Restart Apache
Load the changed module configuration by restarting the service:
sudo systemctl restart apache2.service
If the restart fails, do not test the site until the configuration error is fixed. Ask Apache to report the problem:
sudo apache2ctl configtest
A successful check prints Syntax OK. A failed check names the file and line that must be corrected.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall3. Confirm that Apache loaded it
apache2ctl -M | grep rewrite
The expected listing is:
rewrite_module (shared)
The exact spacing can vary, but the important text is rewrite_module. If no line appears, the command may be querying a different Apache installation than the service you restarted, or the module link is missing. Inspect the enabled-module directory:
ls -l /etc/apache2/mods-enabled/ | grep rewrite
On a normal Ubuntu installation, you should see links for the rewrite module’s load and configuration files. Re-run sudo a2enmod rewrite, then restart and verify again. If the host runs more than one Apache instance, make sure the service name, binary, and configuration path all refer to the same instance.
Rank #2
- Used Book in Good Condition
Allow .htaccess to read rewrite directives
Loading mod_rewrite does not grant permission to process per-directory configuration. Apache’s default policy is commonly AllowOverride None; with that policy, .htaccess files are completely ignored. Add an appropriate directory block for the actual document root or application directory in the virtual-host/server configuration.
Least-privilege setting for rewrite rules
<Directory /var/www/html>
AllowOverride FileInfo
Require all granted
</Directory>
Replace /var/www/html with the real document root. AllowOverride FileInfo permits the rewrite directives normally used in a .htaccess file, including RewriteEngine, RewriteBase, RewriteCond, RewriteOptions, and RewriteRule. Require all granted controls access to the directory; it is separate from rewrite permission and should match the access policy your site needs.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →When, if ever, to use AllowOverride All
AllowOverride All enables a much broader set of per-directory overrides. Use it only when the application genuinely requires those additional directives. It increases the amount of configuration that can be changed by files beneath that directory, which makes auditing and performance analysis harder. Keep the filesystem root at AllowOverride None and change only the directory that hosts the site.
Apply the change safely
- Edit the active virtual-host file or another server-level configuration included by Apache.
- Check syntax:
sudo apache2ctl configtest - Reload when only server configuration changed:
sudo systemctl reload apache2.serviceA full restart is also valid and is required after enabling a module if you have not already restarted.
- Request a URL that exercises the rule and watch the response status and Apache error log while testing.
Create a minimal .htaccess rule
Place the file in the document root (or in the application directory whose <Directory> block permits overrides):
RewriteEngine On
RewriteRule ^old-path/?$ /new-path [R=301,L]
This example sends a permanent redirect from /old-path (with an optional trailing slash) to /new-path. Test with a browser or with:
curl -I http://your-host.example/old-path
You should see a 301 status and a Location header pointing to /new-path. Use a temporary R=302 while developing if you do not want browsers to cache a permanent redirect; change it to 301 only when the destination is final.
Understand per-directory pattern syntax
In .htaccess (per-directory) context, Apache strips the directory prefix before matching a RewriteRule. The pattern therefore does not begin with a leading slash. Write ^old-path$, not ^/old-path$. A leading slash is appropriate in some server or virtual-host contexts only when the rule’s context requires it; always check the context in which the rule runs.
RewriteEngine On enables the runtime engine in the context containing the rules. Without it, the rules are present but inactive. If rules are placed directly in a virtual-host or server configuration, put RewriteEngine On in each relevant virtual host: rewrite configuration is not inherited by virtual hosts.
Per-directory rewriting and symbolic links
Apache’s per-directory rewriting requires at least one of FollowSymLinks or SymLinksIfOwnerMatch to be enabled for that directory. If a deployment uses symbolic links and rules fail despite correct overrides, inspect the directory’s Options policy rather than adding broader overrides blindly. Change only what the deployment’s ownership and security model permits.
Understand effective directory scope
The <Directory> path must match the filesystem location Apache uses after resolving the virtual host’s DocumentRoot. Enabling overrides for a parent directory does not help if the request is served by a different site, a different document root, or a more specific directory policy. This is why apache2ctl -S and the active DocumentRoot should be checked before editing a .htaccess file.
Keep the policy as narrow as the application allows. A site that only needs URL rules normally needs AllowOverride FileInfo, not AllowOverride All. If an application also depends on other per-directory directives, identify those requirements explicitly before expanding the override class. When Apache is configured with AllowOverrideList, make sure the directives used by the file are permitted there as well; a restrictive list can still block a directive even when the module itself is loaded.
There is no separate paid component in this procedure. The commands use Ubuntu’s Apache module layout and Apache configuration directives; the operational cost is limited to applying and testing the configuration on the server.
Choose where rewrite rules should live
| Configuration style | Best fit | Trade-offs |
|---|---|---|
.htaccess |
Shared hosting, delegated application configuration, or situations where the site owner cannot edit the virtual-host file. | Apache checks the file for requests in that directory tree; rules are distributed and depend on AllowOverride permission. |
| Virtual-host/server configuration | Sites you administer centrally, especially high-traffic or multi-site servers. | Centralized control and easier performance analysis, but requires access to Apache’s server configuration and a reload/restart after changes. |
For a centrally managed site, server-level rules avoid delegating configuration through writable application directories. For an application that expects to ship its own .htaccess, grant only the override class it needs and keep the rest of Apache locked down.
Rules in server configuration also make the owning virtual host unambiguous. Because rewrite settings are not inherited by virtual hosts, repeat the relevant RewriteEngine On and rules in every host that needs them. Conversely, do not assume that a rule tested on the default site will apply to a named host simply because both hosts use Apache’s same process.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteWhen a simpler redirect is better than mod_rewrite
Not every redirect needs a regular-expression engine. For a straightforward, unconditional URL move, Apache’s Redirect or RedirectMatch directives are simpler and more efficient than a rewrite rule. Apache documents these alternatives in its URL remapping documentation.
Redirect 301 /old-path /new-path
Use mod_rewrite when you need conditions, captures, environment-based decisions, host or query-string logic, or an internal mapping rather than a client-visible redirect. Choosing the simpler directive reduces the number of moving parts and makes the intended behavior easier to audit.
Rank #4
Troubleshoot rules that are ignored or return HTTP 500
The module is reported as already enabled
Run the restart and verification commands anyway. “Already enabled” refers to the module links, not to whether the currently running process has loaded them. Confirm rewrite_module with apache2ctl -M and make sure that command addresses the same Apache instance as apache2.service.
apache2ctl -M shows no rewrite_module
- Run
sudo a2enmod rewriteagain and read its output for errors. - Inspect
/etc/apache2/mods-enabledfor the rewrite symlinks. - Restart
apache2.service, then repeat the module check. - If multiple installations or custom prefixes exist, compare the binary and configuration used by the service with the one invoked by
apache2ctl.
The .htaccess file is ignored
Check the directory block that matches the real document root. AllowOverride None disables processing; AllowOverrideList None can also prevent directives from being used. Set AllowOverride FileInfo for the relevant directory, validate syntax, and reload Apache. Confirm the file is named exactly .htaccess, is located beneath that directory, and is readable by the Apache process.
Every request returns HTTP 500 after adding the file
A syntax or directive error is usually recorded in Apache’s error log. Inspect the log immediately after reproducing the failure, then run:
sudo apache2ctl configtest
Common causes include a misspelled directive, a directive not permitted by the selected override class, malformed regular-expression syntax, or a rule that creates a redirect loop. Temporarily reduce the file to the two-line minimal example, verify that it works, and add conditions and flags one at a time.
The rule is syntactically valid but never matches
- Remove the leading slash from a per-directory pattern: use
^old-path/?$, not^/old-path/?$. - Check whether the request includes a directory prefix that is stripped before matching.
- Confirm that
RewriteEngine Onappears in the same effective context as the rule. - Check the requested hostname and virtual host. A rule in one site is not inherited by another virtual host.
- Test the exact path, including or excluding a trailing slash and any query string your conditions inspect.
The rule works on one site but not another
Inspect each virtual host separately. Rewrite settings are not inherited between virtual hosts, and each site can point to a different document root and <Directory> policy. Copying a working .htaccess file is not enough if the second site’s directory block still uses AllowOverride None.
Redirects appear cached or loop
A browser may cache a 301. Test with curl -I or a private browser window while developing. Follow the Location headers and verify that the destination does not match the source rule again. Use a temporary 302 during iteration, then switch to 301 only after confirming the final mapping.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →A repeatable enable-and-test checklist
- Identify the hostname, active virtual-host file, and document root with
sudo apache2ctl -S. - Enable the module:
sudo a2enmod rewrite. - Restart Apache:
sudo systemctl restart apache2.service. - Verify loading:
apache2ctl -M | grep rewriteshould showrewrite_module. - For
.htaccess, setAllowOverride FileInfoin the matching<Directory>block and retainRequire all grantedor your site’s intended access rule. - Run
sudo apache2ctl configtestbefore every reload or restart. - Add
RewriteEngine Onand one minimal rule; remember that per-directory patterns omit the leading slash. - Test with
curl -I, inspect the status andLocationheader, and read the error log if the result is unexpected. - Once the behavior is correct, replace temporary redirects with the permanent status you actually intend and document the rule’s purpose.
How to roll back safely
If enabling the module causes an unexpected interaction, disable it with:
sudo a2dismod rewrite
Then validate and restart:
sudo apache2ctl configtest
sudo systemctl restart apache2.service
Disabling the module will make rewrite directives unavailable; remove or disable dependent rules first if they prevent Apache from starting. For a bad site-level change, restore the previous virtual-host or .htaccess version, run the syntax check, and reload. Keeping changes small—module, directory policy, then one rule—makes the failing layer identifiable and the rollback quick.
Best Value
- Used Book in Good Condition
Frequently Asked Questions
Do I need to restart Apache after running a2enmod rewrite?
Yes. a2enmod creates the enabled-module links, but the running Apache process must be restarted with sudo systemctl restart apache2.service before it loads the change.
Why does apache2ctl -M not show rewrite_module after enabling it?
Inspect /etc/apache2/mods-enabled, restart Apache, and confirm that apache2ctl and apache2.service refer to the same installation and configuration. The expected listing contains rewrite_module.
Recommended Free Tools
Why is my .htaccess file ignored even though mod_rewrite is loaded?
Module loading and .htaccess permission are separate. In the matching <Directory> block, AllowOverride None (or a restrictive AllowOverrideList) prevents rewrite directives. Use the narrowest policy that supports the file, normally AllowOverride FileInfo.
Should I use AllowOverride All for WordPress or another application?
Only if the application genuinely needs directives beyond the rewrite-related FileInfo class. AllowOverride All broadens what files beneath the directory can change, so prefer AllowOverride FileInfo when it is sufficient.
Should a RewriteRule pattern in .htaccess start with a slash?
No. In per-directory context Apache removes the directory prefix before matching, so use ^old-path/?$, not ^/old-path/?$.
Why does a rewrite rule work on one virtual host but not another?
Apache does not inherit rewrite configuration between virtual hosts. Check each host’s RewriteEngine On, document root, and matching <Directory> policy separately.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Can I use Redirect instead of mod_rewrite?
For a simple, unconditional URL move, Redirect or RedirectMatch is simpler and more efficient. Use mod_rewrite when conditions, captures, host or query logic, or internal mapping are required.
The Bottom Line
Run sudo a2enmod rewrite, restart Apache, and verify rewrite_module. For .htaccess, separately authorize the actual document root with AllowOverride FileInfo, keep RewriteEngine On in the effective context, and remember that per-directory patterns omit the leading slash.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




