Disable ModSecurity on a Domain via .htaccess
Luke Hebert
- 2 minutes read - 268 wordsModSecurity is a powerful web application firewall, but it can occasionally flag legitimate traffic as malicious. If you need to disable it for a specific domain or path, a single line in your .htaccess file does the job.
Disabling ModSecurity
Add the following directive to the .htaccess file in the directory where you want ModSecurity turned off:
SecRuleEngine OffThat is it. Apache will stop evaluating ModSecurity rules for that directory and everything beneath it.
Scope and Placement
- Domain-wide: Place the directive in the
.htaccessat the document root for that virtual host. - Path-specific: Place it in the
.htaccessinside the subdirectory you want to exclude. - Single file: You can also use a
<Directory>block in the Apache vhost config if you prefer server-level control.
Re-enabling ModSecurity
If you later need to turn it back on, simply remove or comment out the line:
# SecRuleEngine OffThen reload Apache:
sudo systemctl reload apache2Things to Keep in Mind
Disabling ModSecurity removes all WAF protection for the affected path. Only do this for the narrowest scope possible, and re-enable it as soon as the underlying issue is resolved.
- Check your ModSecurity audit logs (
/var/log/modsec_audit.logor equivalent) to identify which rule is triggering the false positive. - If only one rule is the problem, consider using
SecRuleRemoveByIdinstead of turning the entire engine off. - After making changes, test with the same request that was previously blocked to confirm the fix.
This approach gives you a quick, targeted way to stop a specific rule set from interfering with legitimate traffic without pulling the plug on your entire WAF.