phpsecurity.htaccess

Turn off mod_security for a page in shared hosting environment


My page showing error forbidden access error, when I post some html and javascript mixed data by other page post method .

but when I open that page directly its appears correctly without any error.

I know this is server security related issue when I am posting data.

As I searched I found the solution of Turn off mod_security in .htaccess file .

But I want to do this just for this page not for my complete website.

My hosing environment is shared.but I can edit my .htaccess file.


Solution

  • Take a look at some mod_security and .htaccess tricks. There's a lot of different ways you can enable or disable mod_security. The easiest may be to set the MODSEC_ENABLE environment variable to On or Off. You can use SetEnvIf to match against a number of things including the Request_URI:

    SetEnvIf Request_URI your_page\.php$ MODSEC_ENABLE=Off
    

    Or a number of pages:

    SetEnvIf Request_URI ^/directory/file.*\.php$ MODSEC_ENABLE=Off
    

    Or if you need to do something more complicated, like matching against a query string, using mod_rewrite:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} example_param=example_value [NC]
    RewriteRule ^path/your_file\.php$ - [E=MODSEC_ENABLE:Off]