Skip to content

Site throws HTTP 500 right after editing .htaccess on cPanel

A site worked until an .htaccess edit, then every page returned 500. An unsupported directive or a disallowed override is the cause. Here is how to find the bad line and fix it.

When a site that worked a minute ago starts returning HTTP 500 on every page right after you saved an .htaccess file, the file itself is almost certainly the cause. Apache reads .htaccess on every request, and an unknown directive, a directive from a module that is not loaded, or one that AllowOverride does not permit makes Apache abort the request with a 500 — and because .htaccess applies to the whole directory tree below it, the entire site goes down at once. The fix is to identify the offending line from the error log and either correct it, move it where it is allowed, or remove it.

What’s happening

.htaccess is a per-directory configuration file. Apache parses it fresh for every request that touches its directory or anything beneath it, which is why a single bad line takes down every page instantly rather than just one. Three classes of problem produce a 500 from .htaccess: a syntax error or unknown directive (a typo, a copied snippet for a different server, or a Windows/IIS rule pasted into an Apache file); a directive that belongs to a module that is not loaded (a RewriteRule with no mod_rewrite, a Header line with no mod_headers, a php_value on a PHP-FPM or suPHP setup where mod_php is absent); and a directive that AllowOverride forbids for that account, so Apache refuses it.

The php_value / php_flag case is especially common on cPanel. Those directives only work when PHP runs as an Apache module (DSO). On the modern default — PHP-FPM or suPHP — mod_php is not loaded, so a stray php_value memory_limit 256M in .htaccess throws Invalid command 'php_value' and 500s the site. PHP settings there must go in a .user.ini or php.ini instead.

How to verify

The Apache error log names the exact file, line number, and directive. Read it first — this is almost always a one-line diagnosis.

# The error log names the bad directive and the line
tail -30 /home/<cpaneluser>/logs/<domain>.error.log
tail -30 /usr/local/apache/logs/error_log

# Typical signatures:
#   Invalid command 'php_value', perhaps misspelled or defined by a module not included
#   /home/user/public_html/.htaccess: Invalid command 'RewriteRule'
#   .htaccess: <IfModule mod_xyz.c> ... unexpected end of file
#   Options not allowed here

Confirm it is the .htaccess by testing with it disabled — if the 500 clears, you have isolated the cause.

# Disable the file and reload — does the site come back?
mv /home/<cpaneluser>/public_html/.htaccess /home/<cpaneluser>/public_html/.htaccess.bak

# Look at what was in it
cat /home/<cpaneluser>/public_html/.htaccess.bak

Check whether the directive needs a module that is loaded, and what override level the account has:

# Is mod_rewrite / mod_headers actually loaded?
httpd -M 2>/dev/null | grep -iE 'rewrite|headers|php'

# Which PHP handler is in play (php_value only works under DSO/mod_php)?
grep -i "<domain>" /etc/userdatadomains

# Validate overall Apache config after any include-level change
apachectl configtest

The fix

  1. Read the error log and find the line — it names the file, the line number, and the directive verbatim. Do not guess; the Invalid command or not allowed here message tells you exactly which line to fix. This step alone resolves most .htaccess 500s.
  2. php_value / php_flag on a non-DSO handler — the log shows Invalid command 'php_value'. PHP runs as FPM or suPHP, so mod_php is absent. Remove those lines from .htaccess and set the same values in a .user.ini (e.g. memory_limit = 256M) in the document root, or in cPanel » MultiPHP INI Editor. Wrapping them in <IfModule mod_php.c> also silences the error but does not apply the setting.
  3. Directive for an unloaded module — RewriteRule without mod_rewrite, Header without mod_headers. Either enable the module server-wide via EasyApache 4 (WHM » EasyApache 4), or wrap the block in <IfModule mod_rewrite.c> ... </IfModule> so Apache skips it when the module is absent instead of erroring.
  4. Syntax error or foreign rule — a typo, an unterminated <IfModule>, or an IIS web.config-style rule pasted in. Correct the syntax, close every opened block, and remove anything that is not Apache directive syntax. Comparing against a known-good backup of the file pinpoints the bad addition fast.
  5. Options or AllowOverride not permitted — Options not allowed here means the account’s AllowOverride does not grant Options. Either remove the Options line, or have it set at the server level; per-account AllowOverride is controlled in WHM » Apache Configuration » Include Editor / Tweak Settings, not in the file itself.
  6. Roll back to confirm, then reapply minimally — once the site is back with .htaccess disabled, restore the file and re-add directives a few at a time, reloading after each, until the 500 returns. That isolates the exact line without a guessing game. Keep a .bak copy before any further edit.
  7. Validate before walking away — run apachectl configtest if you touched anything at the include level, and reload the page. A .htaccess error is per-request, so a clean reload is sufficient proof for file-level rules; no Apache restart is needed for .htaccess changes.

Once the offending directive is corrected, moved to .user.ini, or wrapped in an <IfModule> guard, reload the page and confirm the error log no longer records the Invalid command line — a clean log on the next request is the proof the file is valid again. Stack Harbor handles cPanel .htaccess and Apache directive triage under cPanel/WHM management — start a conversation.