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
- Read the error log and find the line — it names the file, the line number, and the directive verbatim. Do not guess; the
Invalid commandornot allowed heremessage tells you exactly which line to fix. This step alone resolves most.htaccess500s. php_value/php_flagon a non-DSO handler — the log showsInvalid command 'php_value'. PHP runs as FPM or suPHP, somod_phpis absent. Remove those lines from.htaccessand 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.- Directive for an unloaded module —
RewriteRulewithoutmod_rewrite,Headerwithoutmod_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. - Syntax error or foreign rule — a typo, an unterminated
<IfModule>, or an IISweb.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. OptionsorAllowOverridenot permitted —Options not allowed heremeans the account’sAllowOverridedoes not grantOptions. Either remove theOptionsline, or have it set at the server level; per-accountAllowOverrideis controlled in WHM » Apache Configuration » Include Editor / Tweak Settings, not in the file itself.- Roll back to confirm, then reapply minimally — once the site is back with
.htaccessdisabled, 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.bakcopy before any further edit. - Validate before walking away — run
apachectl configtestif you touched anything at the include level, and reload the page. A.htaccesserror is per-request, so a clean reload is sufficient proof for file-level rules; no Apache restart is needed for.htaccesschanges.
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.