Free tools Windows power users keep installed
One-click scans. No signup required.
Apache usually ignores a .htaccess rewrite for one of four reasons: the selected VirtualHost points at a different directory, the matching <Directory> block disallows overrides, mod_rewrite or RewriteEngine is disabled, or the rule uses server-context syntax in per-directory context. Fix those in that order; RewriteBase is only needed for particular URL-to-filesystem mappings and does not enable rewriting.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
What Apache is doing before it reaches your rule
A request does not begin inside .htaccess. Apache first uses the request’s host information to select a VirtualHost, then maps the request to that host’s DocumentRoot (or another mapping such as an Alias). Server- and VirtualHost-level rewrite directives run during that earlier phase. Apache reads per-directory configuration files, including .htaccess, later during request fixup.
As an Amazon Associate I earn from qualifying purchases.
That order creates two common surprises. First, the .htaccess file must be beneath the filesystem directory selected by the active VirtualHost. A file in the directory you expect is irrelevant if DNS or the request’s Host header selected another host. Second, Apache decides whether it is allowed to read that file from the matching <Directory> policy. If the policy disallows overrides, no rewrite rule inside the file is evaluated at all.
VirtualHost rules also do not automatically inherit rewrite settings from the main server context. The Apache mod_rewrite documentation states: “By default, mod_rewrite configuration settings from the main server context are not inherited by virtual hosts.” Treat every VirtualHost as a separate configuration scope and enable what it needs there.
1. Check the override policy first
Why AllowOverride None makes the file invisible
In current Apache 2.4 behavior, AllowOverride defaults to None. When both AllowOverride None and AllowOverrideList None apply to a directory, Apache says that “.htaccess files are completely ignored.” This happens before mod_rewrite can inspect a single RewriteRule, so changing the rule itself cannot help.
The setting must be in a non-regular-expression <Directory> section that matches the actual filesystem directory used by the selected VirtualHost. A setting for /var/www/other-site does nothing for a host whose document root is /srv/www/game-site.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Permit the rewrite directive class
The broad, conventional permission is:
<Directory '/srv/www/game-site'>
AllowOverride FileInfo
</Directory>
FileInfo permits the rewrite directives normally used in an .htaccess file. If you want a narrower allow-list, use AllowOverrideList and name only the directives required by the file:
<Directory '/srv/www/game-site'>
AllowOverride None
AllowOverrideList RewriteEngine RewriteOptions RewriteBase RewriteCond RewriteRule
</Directory>
Do not put AllowOverride in a VirtualHost block and expect it to work; it is a directory policy. Conversely, changing a directory policy in one VirtualHost does not grant permission to a different host.
Rank #2
- Used Book in Good Condition
Verify the file name and location
- Confirm the file is named exactly
.htaccess, including the leading dot and lowercase spelling, unless the server has changedAccessFileName. - Confirm it is inside the active VirtualHost’s
DocumentRootor an eligible child directory. - Check parent-directory policies as well as the most specific matching
<Directory>section; an inherited restriction can still prevent the file from being read.
2. Make sure the request selected the VirtualHost you edited
Host name and DNS
A rewrite can appear to work on one domain and fail on another because the requests are reaching different VirtualHosts. Confirm that the DNS record resolves to the server you changed and that the request’s Host header matches the intended ServerName or ServerAlias. Test the exact hostname, including whether the request uses www or a bare name.
Use your deployment’s Apache configuration-dump tooling to inspect the active VirtualHost map. The useful result is not merely that a configuration file exists on disk; it is that Apache has loaded the expected host, aliases, DocumentRoot, and matching <Directory> policy.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsDocumentRoot must contain the file you are testing
Suppose the active host has DocumentRoot '/srv/www/site-a/public'. An .htaccess under /srv/www/site-b/public cannot affect that request. Likewise, an .htaccess in the project checkout may be ignored when the VirtualHost serves a separate published directory. Compare the path in the VirtualHost with the filesystem path shown by the file manager or deployment system, not just with the URL you typed.
Aliases and other mappings need extra care
An Alias can map a public URL prefix to a directory outside the document root. In that case, the URL path and filesystem path do not have the same shape. The .htaccess must still be permitted in the mapped directory, and relative substitutions may need an explicit RewriteBase, discussed below.
3. Enable mod_rewrite and the rewrite engine
Loading the module
Apache must have mod_rewrite loaded. A syntactically correct rule has no effect when the module is unavailable; depending on how the configuration is deployed, Apache may reject the configuration or the directives may never be active in the host you are testing. Verify module loading with the configuration inspection method used by your platform.
Turning the engine on
RewriteEngine is off by default. Enable it in the scope that owns the rules:
RewriteEngine On
For a per-directory file, place that line in the applicable .htaccess. For server or VirtualHost rules, place it in that VirtualHost. Enabling the engine in the main server context does not automatically enable or configure it for every VirtualHost.
Separate permission failures from engine failures
If an error log reports that a rewrite directive is not allowed, fix AllowOverride or AllowOverrideList. If the file is accepted but nothing matches, check RewriteEngine On, the pattern context, conditions, and rule order. These are different failure classes and should not be debugged interchangeably.
4. Use the pattern syntax for the context where the rule runs
The same-looking rule is matched against a different string in server/VirtualHost context and in per-directory context.
| Setting | Server or VirtualHost context | .htaccess per-directory context |
|---|---|---|
Path supplied to the initial RewriteRule pattern |
The URL path includes its leading slash, such as /app/index.php. |
Apache removes the directory prefix before matching; the pattern normally has no leading slash. |
| Typical pattern | ^/app/index.php$ |
^app/index.php$ in the document root, or ^index.php$ in an app directory. |
| Directory prefix | Not stripped for the URL-path match. | Stripped before matching and restored while Apache handles the substitution. |
| Most common mistake | Using a pattern intended for a different host or URL map. | Starting the pattern with ^/; it normally cannot match in ordinary .htaccess context. |
For example, this VirtualHost rule and its document-root .htaccess equivalent target the same URL:
# VirtualHost/server context
RewriteRule '^/app/index.php$' '/index.php' [L]
# .htaccess in the document root
RewriteRule '^app/index.php$' 'index.php' [L]
If the .htaccess is inside the app directory itself, Apache has already removed that directory prefix, so the pattern becomes ^index.php$. Moving the file can therefore change which pattern matches even when the public URL is unchanged.
5. Understand what RewriteBase does—and does not do
RewriteBase is not a switch that turns rewriting on. It does not replace AllowOverride, load mod_rewrite, or correct a leading slash in a pattern. Its purpose is to tell Apache the public URL prefix to use when a relative substitution is resolved in per-directory context.
Apache removes the local directory prefix before matching an .htaccess rule and later puts that prefix back while processing the substitution. This normally works when the filesystem directory corresponds directly to its URL path. An Alias or another mapping can break that one-to-one relationship: the directory may be physically located at one path while being published under a different URL prefix.
In that situation, an explicit base can clarify the public prefix:
Recommended Free Tools
RewriteEngine On
RewriteBase /app/
RewriteRule '^old$' 'new' [L]
Use the base that corresponds to the public URL, not the server’s filesystem path. If the substitution is already an absolute URL-path (for example, /new) and no relative resolution is needed, adding RewriteBase is usually unnecessary. Add it only after the host selection, override policy, module, engine, and pattern have been verified.
6. A reliable fix sequence
Work through one known URL and change one layer at a time. This prevents a successful redirect from masking a separate configuration error.
- Identify the host. Confirm the exact hostname, DNS destination, and
Hostheader select the VirtualHost you intend to edit. - Inspect the loaded configuration. Use the Apache configuration-dump tooling provided by your deployment to verify the active VirtualHost, aliases,
DocumentRoot, and directory sections. - Locate the file. Confirm that the tested request maps to the directory containing the exact
.htaccessfilename, or to a mapped directory whoseAccessFileNameis known. - Permit overrides. In the matching non-regex
<Directory>block, setAllowOverride FileInfo, or setAllowOverrideListto includeRewriteEngine,RewriteOptions,RewriteBase,RewriteCond, andRewriteRuleas required. - Verify the module. Confirm
mod_rewriteis loaded by the running Apache instance, not merely enabled in an unused configuration file. - Enable rewriting. Put
RewriteEngine Onin the same applicable.htaccessor VirtualHost scope as the rules. - Correct the pattern. Remove a leading slash from rules that run in
.htaccess; include the directory-relative path that Apache actually matches. - Review substitutions and bases. Use an absolute URL-path where practical. Add
RewriteBaseonly when a relative substitution needs a public URL prefix, especially with an Alias. - Check order and conditions. A rule can be valid but never reached because an earlier rule, condition, or terminating flag handles the request first.
- Reload after server edits. Changes to VirtualHost or directory configuration do not affect the running process until Apache is reloaded or restarted according to your deployment procedure. Then retest one URL with a predictable expected result.
- Read the logs. Review the Apache error log and, where permitted, rewrite trace logging for the selected VirtualHost, pattern result, condition result, and final substitution.
7. Diagnose the symptom instead of guessing
| Symptom | Most likely layer | What to check |
|---|---|---|
| The file can contain any text and nothing changes. | File is not being read. | Active VirtualHost, DocumentRoot, exact .htaccess name, matching <Directory>, and AllowOverride/AllowOverrideList. |
| Apache reports that a rewrite directive is not allowed. | Override class or allow-list. | Permit FileInfo or explicitly list the rewrite directives in AllowOverrideList. |
| The file is accepted, but every rule misses. | Engine or pattern context. | Confirm RewriteEngine On, module loading, and removal of the leading slash in per-directory patterns. |
| One domain works while another does not. | Different VirtualHost or directory policy. | Compare host selection, DocumentRoot, aliases, and the applicable <Directory> sections. |
| A relative substitution goes to the wrong URL under an Alias. | URL-to-filesystem prefix mismatch. | Use the correct public prefix with RewriteBase, or use an appropriate absolute URL-path substitution. |
A server-context rule works, but the copied .htaccess rule does not. |
Different matching context. | Remove ^/ from the per-directory pattern and account for the directory prefix Apache strips. |
| A change appears to have no effect after editing the VirtualHost. | Running process still has old configuration. | Reload or restart Apache, then test again and inspect the active configuration. |
8. Decide whether the rule belongs in the VirtualHost or in .htaccess
| Criterion | VirtualHost/server configuration | .htaccess |
|---|---|---|
| Access required | Permission to edit and reload the main Apache configuration. | No main-config access, provided the host permits the necessary overrides. |
| Scope | Whole host, with explicit control over host-wide ordering. | The directory containing the file and its eligible child paths. |
| Rule syntax | URL-path patterns normally include the leading slash. | Per-directory patterns normally omit the leading slash. |
| Ordering and auditability | Centralized scope and ordering are easier to inspect. | Rules can be delegated and changed locally, but may be distributed across directories. |
| Applying changes | Requires a reload or restart after server-configuration edits. | Typically read per request once permitted, while changes to the surrounding server policy still require a reload. |
| Provider support | Unavailable on hosting where customers cannot edit VirtualHosts. | Works only when the provider allows the required override class or directive list. |
When you control the main configuration, Apache recommends a dedicated VirtualHost and a simple Redirect for a straightforward host-wide redirect. Central configuration keeps scope and ordering visible. Use .htaccess when main-config access is unavailable or when behavior genuinely belongs to one delegated directory.
9. Minimal known-good configurations
Document-root .htaccess
RewriteEngine On
RewriteRule '^old-page$' '/new-page' [R=301,L]
This example assumes the file is in the document root, the matching directory permits FileInfo (or the listed directives), and the requested path is /old-page. The pattern has no leading slash because it is per-directory.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →VirtualHost configuration
<VirtualHost *:80>
ServerName example.test
DocumentRoot '/srv/www/game-site'
<Directory '/srv/www/game-site'>
AllowOverride FileInfo
</Directory>
RewriteEngine On
RewriteRule '^/old-page$' '/new-page' [R=301,L]
</VirtualHost>
Here the pattern includes the leading slash because the rule runs in VirtualHost context. If you move the rule into the document-root .htaccess, remove that slash and keep the override policy that permits it.
Quick Recap
10. What not to change blindly
- Do not add
RewriteBaseas a universal remedy. It cannot make an ignored file run. - Do not copy a leading slash from a VirtualHost rule into
.htaccess. The matching string is different. - Do not edit an unrelated
<Directory>block. The policy must match the filesystem directory selected by the active host. - Do not assume a main-server setting reaches every host. Rewrite settings are not inherited into VirtualHosts by default.
- Do not debug conditions before confirming the file is eligible. A denied override or wrong document root prevents every condition and rule from running.
Final verification checklist
- The request’s hostname selects the intended VirtualHost.
- That VirtualHost’s
DocumentRootor mapping contains the tested.htaccess. - The file name matches
AccessFileName. - The matching
<Directory>permitsFileInfoor the required rewrite directives. mod_rewriteis loaded andRewriteEngine Onis present in the rule’s scope.- Per-directory patterns omit the leading slash.
RewriteBaseis used only for a genuine relative URL-prefix mismatch.- Rule order, conditions, flags, logs, and the post-edit reload have all been checked.
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.




