Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

Why Apache VirtualHost Ignores .htaccess Rewrites (and How to Fix It)

Apache ignores .htaccess rewrites when the wrong VirtualHost or directory is selected, overrides are disabled, mod_rewrite is off, or per-directory patterns use the wrong syntax. This guide provides a precise diagnostic sequence and working configurations.
Length10 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Verify the file name and location

  • Confirm the file is named exactly .htaccess, including the leading dot and lowercase spelling, unless the server has changed AccessFileName.
  • Confirm it is inside the active VirtualHost’s DocumentRoot or 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

DocumentRoot 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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# 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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

  1. Identify the host. Confirm the exact hostname, DNS destination, and Host header select the VirtualHost you intend to edit.
  2. Inspect the loaded configuration. Use the Apache configuration-dump tooling provided by your deployment to verify the active VirtualHost, aliases, DocumentRoot, and directory sections.
  3. Locate the file. Confirm that the tested request maps to the directory containing the exact .htaccess filename, or to a mapped directory whose AccessFileName is known.
  4. Permit overrides. In the matching non-regex <Directory> block, set AllowOverride FileInfo, or set AllowOverrideList to include RewriteEngine, RewriteOptions, RewriteBase, RewriteCond, and RewriteRule as required.
  5. Verify the module. Confirm mod_rewrite is loaded by the running Apache instance, not merely enabled in an unused configuration file.
  6. Enable rewriting. Put RewriteEngine On in the same applicable .htaccess or VirtualHost scope as the rules.
  7. Correct the pattern. Remove a leading slash from rules that run in .htaccess; include the directory-relative path that Apache actually matches.
  8. Review substitutions and bases. Use an absolute URL-path where practical. Add RewriteBase only when a relative substitution needs a public URL prefix, especially with an Alias.
  9. Check order and conditions. A rule can be valid but never reached because an earlier rule, condition, or terminating flag handles the request first.
  10. 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.
  11. 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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

10. What not to change blindly

  • Do not add RewriteBase as 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 DocumentRoot or mapping contains the tested .htaccess.
  • The file name matches AccessFileName.
  • The matching <Directory> permits FileInfo or the required rewrite directives.
  • mod_rewrite is loaded and RewriteEngine On is present in the rule’s scope.
  • Per-directory patterns omit the leading slash.
  • RewriteBase is 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.