October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

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

Apache usually ignores .htaccess rewrites because the wrong VirtualHost is selected, overrides are disabled, mod_rewrite is off, or a server-context pattern was copied into a per-directory file. This guide shows how to diagnose and fix each cause.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache usually “ignores” an .htaccess rewrite for one of three reasons: the request is reaching a different VirtualHost than expected, that host’s matching <Directory> policy disables or restricts overrides, or the rule uses VirtualHost syntax inside a per-directory file. Apache can also skip the rules when mod_rewrite is not loaded or when RewriteEngine remains off.

Fix the problem in this order: verify the selected host and its DocumentRoot, make the .htaccess file eligible with AllowOverride or AllowOverrideList, enable mod_rewrite, adapt rule patterns to per-directory matching, and only then investigate rule order, conditions, substitutions and flags. RewriteBase is sometimes useful for URL-to-filesystem mappings, but it does not enable rewriting.

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.

How Apache decides whether .htaccess can run

Apache does not evaluate every rewrite rule in one universal context. A request passes through several configuration stages, and the stage that reads .htaccess comes after Apache has selected a VirtualHost and mapped the URL to a directory.

  1. Host selection: Apache uses the connection’s address, port and HTTP Host header to select a VirtualHost. DNS only points a name at an address; it does not guarantee that the intended VirtualHost wins.
  2. Filesystem mapping: The selected host’s DocumentRoot, aliases and other mappings determine which directory corresponds to the requested URL.
  3. Directory policy: Apache checks the matching <Directory> configuration to decide whether per-directory configuration files may contribute directives.
  4. Per-directory processing: If the file is permitted, Apache reads .htaccess during request fixup and evaluates its rewrite rules in that directory context.

Consequently, a perfectly written rule can appear dead when the request lands on another host, when the file is outside the selected document root, or when the applicable directory policy tells Apache to ignore override files before mod_rewrite sees a rule.

Server- and VirtualHost-level rewrite directives run earlier than per-directory rules. Their ordering affects which URL path a rule sees and whether an earlier redirect or rewrite changes the request before the .htaccess file is reached.

Check the override policy first

In Apache 2.4, AllowOverride defaults to None. Apache’s core documentation states: “When this directive is set to None and AllowOverrideList is set to None, .htaccess files are completely ignored.” That means Apache does not report a failed rewrite match; it simply never loads the file’s directives.

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

Use the correct directory block

Override settings are valid in a non-regular-expression <Directory> section. The section must match the actual filesystem directory used by the selected VirtualHost, not merely the public URL. For a host whose document root is /srv/www/example/public, a typical policy is:

<Directory "/srv/www/example/public">
    AllowOverride FileInfo
    Require all granted
</Directory>

The path in the <Directory> block is an example; replace it with the real directory and preserve the host’s existing access controls. A policy for a parent directory may also affect the result, so inspect the complete active configuration rather than assuming the nearest-looking block is the only one that applies.

Choose between AllowOverride and AllowOverrideList

Setting What it permits When it fits
AllowOverride None Disables all .htaccess directives in the matching directory. Use when configuration is controlled centrally and per-directory files should not be able to change server behavior.
AllowOverride FileInfo Allows directives in the FileInfo class, including the rewrite directives normally used in .htaccess. A practical choice when applications need URL rewriting but do not need every override class.
AllowOverrideList Allows an explicit list of directives, such as RewriteEngine, RewriteOptions, RewriteBase, RewriteCond and RewriteRule. Use for a narrow allow-list when the server administrator wants tighter control than a whole override class.

Do not assume that adding a rule to .htaccess can bypass a provider’s policy. If the matching directory has both AllowOverride None and AllowOverrideList None, the file is ignored regardless of its contents. The administrator must change the server configuration or provide another supported mechanism.

Confirm the filename

The conventional name is exactly .htaccess, including the leading dot and lower-case letters. Apache can be configured with a different AccessFileName; if so, use that configured name instead. A file called htaccess, .HTACCESS or .htaccess.txt is not the conventional file Apache will read.

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

Make sure the rewrite engine and module are active

mod_rewrite is a module, and its engine is a separate switch. Apache documents RewriteEngine off as the default. A permitted file still does nothing until the engine is enabled in the context where the rules are written:

RewriteEngine On

The module must also be loaded by the running server. The exact enablement procedure depends on the operating system and packaging, so use the deployment’s module-management method and verify the active module list. A configuration test and a graceful reload are required after changing server-level files; an already-running process does not automatically reread them.

Settings in the main server context are not inherited by VirtualHosts by default. Apache’s mod_rewrite documentation puts it plainly: “By default, mod_rewrite configuration settings from the main server context are not inherited by virtual hosts.” Therefore, enabling or configuring rewriting globally does not prove that the selected VirtualHost has the expected settings. Put the needed directives in that VirtualHost or in an eligible per-directory file, and confirm which configuration is active.

Use per-directory RewriteRule syntax in .htaccess

The same-looking rule can match in one context and fail in another because Apache supplies a different string to the pattern.

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.
Where the rule is written What the pattern sees Typical pattern
Server or VirtualHost context The URL path includes its leading slash. ^/app/index.php$
.htaccess in the document root Apache removes the directory prefix and normally removes the leading slash. ^app/index.php$
.htaccess inside an app directory The directory prefix has already been removed. ^index.php$

A pattern beginning with ^/ therefore normally fails in an ordinary .htaccess context. Remove the slash and account for the directory that contains the file. For example, a document-root file might contain:

RewriteEngine On
RewriteRule ^app/index.php$ /index.php [L]

The substitution and flags still need to fit the application. The example demonstrates only the pattern context; it is not a universal redirect or front-controller recipe.

Directory nesting matters. Moving the same file from the document root into /app changes the string presented to the rule. When troubleshooting, write down the exact directory containing the file and test the relative path Apache will pass to its pattern.

Understand when RewriteBase is needed

In per-directory context Apache removes the local directory prefix before matching and later restores it while processing a relative substitution. This is why many ordinary document-root rules work without RewriteBase.

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

Add an explicit base when the public URL prefix is not directly represented by the filesystem path, especially when an Alias or another mapping connects a URL such as /app/ to a directory elsewhere on disk. For example:

RewriteEngine On
RewriteBase /app/
RewriteRule ^index.php$ index.php [L]

The appropriate value is the public URL prefix, not the physical path. RewriteBase /var/www/app/ would be wrong if the browser reaches the application at /app/. RewriteBase does not turn on the engine, grant permission to read the file, load mod_rewrite or repair a pattern with an incorrect leading slash. Treat it as a URL-prefix aid for relative substitutions, not as a general fix.

A complete repair procedure

Follow these checks in sequence so that a later rule-level diagnosis is not confused by an earlier configuration failure.

  1. Verify the hostname and port. Confirm the browser is requesting the intended name and that the request’s Host header should select the expected VirtualHost. If several hosts share an address, inspect the active Apache configuration with the configuration-dump tool supplied by your deployment and identify the host selected for that name.
  2. Record the selected DocumentRoot. Compare the selected VirtualHost’s DocumentRoot with the directory where the file actually exists. If an Alias serves the URL, identify the mapped directory instead of assuming the document root is involved.
  3. Check the access-file name. Confirm the file is exactly .htaccess, or use the configured AccessFileName if the server deliberately uses another name.
  4. Inspect the matching Directory policy. In the non-regex <Directory> section for the real filesystem path, set AllowOverride FileInfo or an AllowOverrideList containing every rewrite directive the file uses. Ensure another applicable section does not reduce the permission back to None.
  5. Check module availability. Verify that the running Apache process has mod_rewrite loaded. Installing a package or editing an unused configuration file does not change the already-running process.
  6. Enable the engine. Put RewriteEngine On in the VirtualHost or eligible .htaccess context containing the rules.
  7. Normalize the pattern. Remove the leading slash from rules in .htaccess, then adjust the pattern for the file’s directory. Keep a leading slash only for a server- or VirtualHost-context pattern that expects it.
  8. Evaluate substitutions and RewriteBase. Use a URL path for an external redirect. For a relative internal substitution, decide whether an Alias or other mapping requires an explicit RewriteBase.
  9. Review order, conditions and flags. A preceding rule may stop processing with [L], a condition may be false, or a substitution may send the request into a new pass. Put the most specific rules before broad catch-alls and verify each condition against the actual request.
  10. Reload and test one URL. After server-configuration edits, run the deployment’s syntax check, reload or restart Apache as appropriate, and request one known URL. Change one variable at a time so the result identifies the failing layer.
  11. Read diagnostics. Inspect the Apache error log for configuration and permission failures. Where the administrator permits rewrite trace logging, enable it temporarily and at an appropriate level to observe the selected context, pattern evaluation, condition result and substitution; disable verbose tracing after the test.

VirtualHost configuration or .htaccess?

Both locations can implement rewriting, but they solve different administration problems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision point VirtualHost or server configuration .htaccess
Required privilege Requires administrator access to Apache’s main configuration and permission to reload it. Useful when a hosting provider grants file access but not server-configuration access; it still requires the provider to permit the needed overrides.
Scope Can cover the whole host and can be placed precisely alongside other host rules. Applies to one directory and its eligible descendants.
Pattern context URL-path patterns normally include the leading slash. Directory prefixes and the leading slash are removed before matching.
Ordering and auditability Centralized rules are easier to review with the selected VirtualHost and its other directives. Rules are distributed through the filesystem and are processed later, after host-level rules.
Change activation Server edits require a syntax check and reload or restart. Changes are read per request once the file is allowed, although server-level policy changes still require a reload.
Provider support Not available on hosting plans that hide the main configuration. Works only when the provider enables the relevant override class or directive allow-list.

When you control the main configuration, Apache recommends a dedicated VirtualHost and a simple Redirect for straightforward host-wide redirects. Use .htaccess for directory-local behavior or delegated hosting where changing the VirtualHost is not possible and the provider explicitly permits the required directives.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Symptoms and the most likely causes

The file appears completely inert

Start with AllowOverride, AllowOverrideList, the exact filename and the selected filesystem directory. A disabled override policy prevents every directive in the file from taking effect, so changing a regular expression cannot solve this symptom.

Apache returns a 500 error immediately after adding a rule

An internal configuration error usually means the directive is not permitted in that context, the module is unavailable, or the syntax is invalid. Read the error log, confirm the directive is included in the allowed class or list, and run the server’s configuration test before reloading.

A rule works in the VirtualHost but not in .htaccess

Compare the pattern context first. Remove the leading slash, account for the directory prefix already removed by Apache, and then check whether the .htaccess file is eligible. Also remember that host-level rules run earlier and can change or finish the request before the per-directory pass.

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

The rule works on one domain but not another

Do not assume the two domains share a configuration. Verify each request’s selected VirtualHost, DocumentRoot, Alias mappings, directory policy, module settings and access-file location. A different host can legitimately have a different override decision even when the files look identical.

A relative substitution creates an unexpected URL

Check whether the public URL prefix differs from the physical directory. An Alias or similar mapping may require RewriteBase with the public prefix. Also inspect whether the substitution should be an absolute URL-path redirect instead of a relative internal path.

Adding RewriteBase changes nothing

That result is expected when the real failure is an ignored file, a disabled engine, an unloaded module, a wrong pattern or a false condition. Resolve those gates first; use RewriteBase only for the relative-substitution mapping case it addresses.

Minimal diagnostic examples

Document-root .htaccess

RewriteEngine On

# The pattern has no leading slash in per-directory context.
RewriteRule ^old-page/?$ /new-page [R=301,L]

This form is appropriate only when the file is in the document root and the intended behavior is an external redirect. A permanent redirect should be introduced only after testing with a temporary status or a controlled client, because browsers may cache a 301.

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

VirtualHost rule

<VirtualHost *:80>
    ServerName example.test
    DocumentRoot "/srv/www/example/public"

    RewriteEngine On
    RewriteRule ^/old-page/?$ /new-page [R=301,L]

    <Directory "/srv/www/example/public">
        AllowOverride FileInfo
        Require all granted
    </Directory>
</VirtualHost>

Here the pattern includes the leading slash because it is written in VirtualHost context. The example also shows why the <Directory> path must correspond to the physical document root. Existing access and security directives may be required in a real deployment; do not replace them casually.

Alias-style mapping

Alias /app/ "/srv/apps/current/public/"

<Directory "/srv/apps/current/public/">
    AllowOverride FileInfo
    Require all granted
</Directory>

For an application reached under /app/, a per-directory rule may need RewriteBase /app/ when its relative substitution otherwise resolves against the physical mapping. The directory policy still has to allow the file, and the rule pattern still follows per-directory syntax.

What to retain when troubleshooting

  • An .htaccess file can be ignored before any rewrite rule is evaluated when the matching directory sets both override controls to None.
  • RewriteEngine is off by default, and main-server rewrite settings do not automatically flow into every VirtualHost.
  • A leading slash belongs in ordinary server or VirtualHost URL-path patterns, not in normal per-directory patterns.
  • RewriteBase fixes a URL-prefix mapping for relative substitutions; it is not an activation switch.
  • VirtualHost rules run before per-directory processing, so request order and the selected host matter as much as the regular expression.

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 *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.