Skip to content

AllowOverride on cPanel: why .htaccess is ignored

AllowOverride decides which .htaccess directives Apache obeys. Find which cPanel include sets it and allow more for one account only.

AllowOverride is the Apache setting that decides which .htaccess directives Apache obeys, and on a cPanel or WHM server it is almost always the reason a directive in .htaccess does nothing and leaves no trace in any log. Apache 2.4 honours only the categories of directive you have allowed: None, All, or a list drawn from AuthConfig, FileInfo, Indexes, Limit and Options. With AllowOverride None, Apache does not open the file at all, so there is nothing to log. WordPress permalinks are the most common case: the rewrite block is present and correct, and has no effect. The steps below find which include in the cPanel Apache configuration sets the policy, then allow more overrides for one account in a place that survives the next configuration rebuild.

What you’ll accomplish

  • A definite answer to whether Apache is reading the account’s .htaccess at all, in one command.
  • The exact file and line of the AllowOverride that currently governs the document root.
  • A mapping from the directive you are trying to use to the override class it belongs to.
  • A per-account override that cPanel regenerates rather than erases.
  • A validation pass that proves the change holds through a full config rebuild.

Prerequisites

Root shell on a cPanel or WHM server running EasyApache 4 with Apache 2.4. Everything below reads and writes under /etc/apache2/, which no account-level user can touch, and the repair uses cPanel’s own maintenance scripts under /scripts/.

If the server runs LiteSpeed instead of Apache, most of this still applies with one caveat worth stating early. LiteSpeed Web Server reads the same Apache configuration, including AllowOverride, and it does read .htaccess — but it caches the parsed result in memory, so a change that is correct can appear not to have landed until the server is restarted. The diagnosis is identical; the “did it work” step needs an extra restart.

On nginx, AllowOverride has no meaning at all. nginx has no .htaccess mechanism; a rewrite rule there lives in a server block and applies on reload. If you are staring at an .htaccess on an nginx host, nothing is reading it, and no override setting will change that.

Throughout, cpuser stands for the cPanel account name and example.com for the domain. Substitute both. Take a copy of the .htaccess before you edit it — step 1 deliberately breaks the file.

How it works

AllowOverride answers one question per directory: which classes of directive is a .htaccess file allowed to change here? The classes are fixed. FileInfo covers document handling and rewriting — RewriteEngine, RewriteRule, RewriteCond, RewriteBase, ErrorDocument, AddType, Header. AuthConfig covers authentication — AuthType, AuthName, AuthUserFile, Require. Indexes covers directory index behaviour, Limit covers the old Order/Allow/Deny host controls, and Options covers the Options directive itself, usually written as Options=Indexes,FollowSymLinks,MultiViews to allow only named values. All grants every class. None grants nothing and, importantly, stops Apache opening the file — which is why the silent failure is silent. The full class list is in Apache’s core directives reference.

The setting only appears in <Directory> sections, never in <Location> or <Files>, and it does not accumulate. It applies to a directory and everything under it until a closer <Directory> block says otherwise, and the closest match wins outright — a <Directory "/home/cpuser/public_html"> block with AllowOverride FileInfo completely replaces an AllowOverride All set on /home, rather than adding to it. That single rule explains most of the confusion: people find one permissive AllowOverride in the config, assume it applies, and never look for the narrower block underneath it.

Apache 2.4.8 added AllowOverrideList, which names individual directives rather than whole classes. It is the honest answer when a customer needs exactly one thing. AllowOverride None paired with AllowOverrideList Redirect RedirectMatch permits those two directives and nothing else, which is a much smaller grant than turning on all of FileInfo.

How cPanel assembles the Apache configuration: EasyApache templates, WHM includes and per-account userdata combine into a generated httpd.conf that sets the effective override policy

On cPanel none of this lives in a file you own. /etc/apache2/conf/httpd.conf is generated. cPanel renders it from templates under /var/cpanel/templates/apache2_4/, folds in whatever the WHM Include Editor has stored under /etc/apache2/conf.d/includes/, and then, per virtual host, pulls in per-account fragments from /etc/apache2/conf.d/userdata/. Edit the generated file directly and your change works until the next account creation, SSL renewal, EasyApache update or /scripts/rebuildhttpdconf — at which point it is gone, usually at a time nobody connects to the edit you made weeks earlier.

The userdata tree is the supported place to put a per-account override. Its shape is /etc/apache2/conf.d/userdata/<scope>/2_4/<user>/<domain>/<name>.conf, where <scope> is std for the plain HTTP virtual host and ssl for the HTTPS one. Almost all real traffic is HTTPS, so a fragment written only into std looks like it did nothing — a mistake worth checking for before you go hunting anywhere else.

Decision tree from a silently ignored htaccess directive through a deliberate syntax error to four distinct causes and their fixes

Step-by-step

  1. Prove the file is being ignored, rather than merely wrong. Append a line that cannot possibly parse. If Apache reads the file, the request must fail with a 500; if the page loads normally, the file was never opened.

    cp /home/cpuser/public_html/.htaccess /root/htaccess.bak
    echo 'ZZZ_not_a_directive' >> /home/cpuser/public_html/.htaccess
    curl -s -o /dev/null -w '%{http_code}\n' https://example.com/

    500 means Apache parsed the file and the override policy is not the whole story — go to step 2. 200 means the file is invisible to Apache: either AllowOverride None applies, or the file cannot be read. Either way, restore it before continuing.

    cp /root/htaccess.bak /home/cpuser/public_html/.htaccess
    curl -s -o /dev/null -w '%{http_code}\n' https://example.com/

    The second command should print 200 again.

  2. Read what Apache actually complained about. When the file is parsed but a directive is not permitted, Apache says so in the main error log, and the message is precise.

    tail -40 /etc/apache2/logs/error_log | grep -i htaccess

    Two lines matter. .htaccess: RewriteEngine not allowed here means the class is missing from AllowOverride — this article’s fix. .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration means the class is fine and the module is not loaded, which is a different repair entirely.

  3. Raise the log level when the rules parse but behave unexpectedly. Rewrite tracing is verbose and belongs in a maintenance window, but it shows every rule evaluation.

    /usr/sbin/httpd -M | grep -E 'rewrite|auth_basic'

    Expect rewrite_module (shared) and auth_basic_module (shared) in the output. A missing line here is the answer to the Invalid command case above. To trace the rules themselves, add LogLevel warn rewrite:trace3 to the userdata fragment you create in step 6, restart, reproduce, then remove it — the trace writes several lines per request per rule.

  4. Dump the configuration Apache is actually running. The generated file includes others, and the include order determines which <Directory> block is closest to the document root.

    /usr/sbin/httpd -t -D DUMP_INCLUDES

    The output starts with Included configuration files: and prints an indented tree beginning at /etc/apache2/conf/httpd.conf. Every file in that tree is a candidate. Then find the virtual host itself, with the file and line number cPanel generated it at:

    /usr/sbin/apachectl -S 2>&1 | grep example.com

    Expect a pair of lines like port 80 namevhost example.com (/etc/apache2/conf/httpd.conf:1284) and the matching port 443 entry. Note both line numbers; the HTTPS vhost is the one your browser is hitting.

  5. Find every AllowOverride that could apply to the document root. Search the whole assembled tree, not just the main file.

    grep -rn 'AllowOverride' /etc/apache2/conf/httpd.conf /etc/apache2/conf.d/ 2>/dev/null

    You will typically see a server-wide AllowOverride None on <Directory "/">, a permissive value emitted by the EasyApache template for each document root, and — on a hardened build — a narrower value in a Pre VirtualHost include. Match each hit to the <Directory> path it sits in and pick the longest path that contains /home/cpuser/public_html. That block is the one in force.

  6. Write the override into the per-account userdata tree. This is the only edit here that a rebuild will not discard. Create the fragment for both the HTTP and HTTPS virtual hosts.

    mkdir -p /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com
    mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com

    Then write the block. Grant the class the directive needs and stop there — a WordPress permalink block needs FileInfo and nothing more.

    printf '%s\n' '<Directory "/home/cpuser/public_html">' '    AllowOverride FileInfo Indexes Limit' '</Directory>' > /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com/allowoverride.conf
    cp /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com/allowoverride.conf /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com/allowoverride.conf
    cat /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com/allowoverride.conf

    The cat should print the three lines back. Fix ownership so the rebuild can read them:

    chown -R root:root /etc/apache2/conf.d/userdata/std/2_4/cpuser /etc/apache2/conf.d/userdata/ssl/2_4/cpuser
    chmod 644 /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com/allowoverride.conf /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com/allowoverride.conf
  7. Wire the fragment into the account’s virtual hosts. Creating the file is not enough; cPanel has to emit the Include lines that reference it.

    /scripts/ensure_vhost_includes --user=cpuser

    The script validates every userdata file for the account and rebuilds the configuration to reference it. If it reports a syntax problem, it names the file — fix that before going further. If you also changed anything under /etc/apache2/conf.d/includes/, regenerate the main file explicitly:

    /scripts/rebuildhttpdconf

    Expect Built /etc/apache2/conf/httpd.conf OK.

  8. Check syntax before you restart, not after. A configuration that fails to parse takes every site on the server down until someone notices.

    /usr/sbin/apachectl configtest

    The only acceptable output is Syntax OK. Then restart through cPanel’s service manager, so its monitoring agrees the service is up:

    /scripts/restartsrv_httpd

    It prints a restart notice followed by a status line confirming httpd is running with a PID. If it reports the service as down, re-run configtest and read the error before trying again.

Validate it works

Start by proving Apache now opens the file, using the same test as step 1 — this time the 500 is the success signal.

echo 'ZZZ_not_a_directive' >> /home/cpuser/public_html/.htaccess
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/
cp /root/htaccess.bak /home/cpuser/public_html/.htaccess

Then exercise the directive that was failing. For WordPress permalinks, request a post by its pretty URL and check that no redirect was needed:

curl -s -o /dev/null -w '%{http_code} %{num_redirects}\n' https://example.com/sample-post/

200 0 is the result you want. For an authentication block, request a protected path and confirm the challenge appears:

curl -s -o /dev/null -w '%{http_code}\n' https://example.com/private/

That should print 401, not 200 or 500.

Now prove the change survives regeneration, which is the part people skip. Count the references, rebuild, and count again:

grep -c 'userdata/std/2_4/cpuser' /etc/apache2/conf/httpd.conf
/scripts/rebuildhttpdconf
grep -c 'userdata/std/2_4/cpuser' /etc/apache2/conf/httpd.conf
/usr/sbin/apachectl configtest

Both counts should be the same non-zero number, and configtest should still print Syntax OK. If the second count is 0, the fragment is in the wrong path or ensure_vhost_includes never accepted it.

Troubleshooting

The account-level block exists but changes nothing. A <Directory> further down the tree is overriding it — commonly a security hardening include that scopes AllowOverride None to /home/*/public_html/wp-content/ or similar. Re-run the grep from step 5 and sort the hits by path length; the longest matching path wins, not the last one written. If a hardening include is genuinely narrower than your fragment, the fix belongs in that include, not in userdata.

.htaccess is present but Apache skips it in silence. Apache reads the file as the account user under suEXEC or CageFS, and a file it cannot read is treated as absent — no error, no log line. Check with ls -l /home/cpuser/public_html/.htaccess; you want cpuser cpuser ownership and mode 644. A file left root root 600 by a hurried restore behaves exactly like AllowOverride None. The file permission and ownership baseline covers the whole account in one pass.

Invalid command in the error log after you widened the class. The class is now permitted and Apache is trying to process the directive, but the module that defines it is not loaded. Confirm with /usr/sbin/httpd -M, then add the module in WHM under EasyApache 4 and rebuild the profile. mod_rewrite and mod_auth_basic are the two that go missing on trimmed profiles. Never work around this by dropping the directive into the vhost instead — it fails there too, and louder.

The fragment vanished after a rebuild. Three causes, in order of likelihood: the path used 2.4 instead of 2_4, the directory was created under the domain’s alias rather than its primary domain name, or ensure_vhost_includes was never run so nothing ever referenced the file. Confirm the exact domain string cPanel uses with grep -l example.com /var/cpanel/userdata/cpuser/* before recreating the directory.

LiteSpeed shows the old behaviour after a correct change. LSWS parses .htaccess once and holds the result. Restart it and retest before assuming the configuration is wrong; if the account also runs PHP through lsphp, a worker holding stale state can add to the confusion, which stuck lsphp processes on cPanel covers separately.

When this is the wrong approach

.htaccess is not free. With any value other than None, Apache walks every directory from the document root down to the requested file and stats a .htaccess in each one, on every single request. A deeply nested application on a busy account pays that cost thousands of times a second, and no amount of caching in front of it removes the stat calls. If the rule never changes and you have root, put it in the virtual host — a userdata fragment holds RewriteRule blocks just as happily as it holds AllowOverride, and Apache parses it once at startup instead of once per directory per request.

Widening the class server-wide is almost never the right call either. AllowOverride All across /home hands every account on the box the ability to change Options, set handlers and turn on directory listings, which is a multi-tenant security decision dressed up as a convenience. Scope it to the account that needs it. If a single directive is all that is wanted, AllowOverrideList is a far smaller grant than a whole class — see the directory listing controls article for the Indexes case in particular.

And if the underlying request is “make WordPress permalinks work”, check the plugin layer before touching Apache. A security plugin that rewrites .htaccess on every save will undo your work on its own schedule; the durable fix is to stop it writing the file, not to widen what it may write. cPanel’s guidance on the userdata tree and the rebuild scripts is at docs.cpanel.net.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.