Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable mod_security in .htaccess file?

How can we disable mod_security by using .htaccess file on Apache server?

I am using WordPress on my personal domain and posting a post which content has some code block and as per my hosting provider said mod_security gives an error and my IP has gone into firewall because of mod_security.

So I want to disable mod_security by using .htaccess file.

like image 453
Gaurav Agrawal Avatar asked Oct 17 '12 06:10

Gaurav Agrawal


People also ask

Should I disable Mod_security?

We will not recommend to disable Mod-Security on your account. Mod_security module helps to protect your website from various attacks. If mod-security is disabled on your account, your website will be at risk from vulnerabilities.

How do I disable Modecurity rules?

How do you turn off ModSecurity rules based on IP? You can turn off ModSecurity rules based on IP. Get your public IP by using https://anto.online/tools/what-is-my-public-ip/. You can find this configuration file in: /etc/modsecurity/modsecurity.

What is Mod_security in Apache?

Mod_security is an apache module that helps to protect your website from various attacks. It is used to block commonly known exploits by use of regular expressions and rule sets and is enabled on all InMotion web hosting plans.

What is the use of Mod_security?

ModSecurity is a free and open source web application that started out as an Apache module and grew to a fully-fledged web application firewall. It works by inspecting requests sent to the web server in real time against a predefined rule set, preventing typical web application attacks like XSS and SQL Injection.


2 Answers

It is possible to do this, but most likely your host implemented mod_security for a reason. Be sure they approve of you disabling it for your own site.

That said, this should do it;

<IfModule mod_security.c>   SecFilterEngine Off   SecFilterScanPOST Off </IfModule> 
like image 100
Xyon Avatar answered Sep 25 '22 15:09

Xyon


On some servers and web hosts, it's possible to disable ModSecurity via .htaccess, but be aware that you can only switch it on or off, you can't disable individual rules.

But a good practice that still keeps your site secure is to disable it only on specific URLs, rather than your entire site. You can specify which URLs to match via the regex in the <If> statement below...

### DISABLE mod_security firewall ### Some rules are currently too strict and are blocking legitimate users ### We only disable it for URLs that contain the regex below ### The regex below should be placed between "m#" and "#"  ### (this syntax is required when the string contains forward slashes) <IfModule mod_security.c>   <If "%{REQUEST_URI} =~ m#/admin/#">     SecFilterEngine Off     SecFilterScanPOST Off   </If> </IfModule> 
like image 43
Simon East Avatar answered Sep 25 '22 15:09

Simon East