I know I can inspect GET query string parameters in rewritecond as follows:
RewriteCond %{REQUEST_URI} ^/somepath/somepath
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} try=3
RewriteCond %{QUERY_STRING} name=([^&]*)
RewriteRule ^/somepath/somepath(.*) /otherpath/otherpath?name=%1 [R]
How do I inspect POST parameters that are in the request body? I hear mod_security can do it, but I'm not finding any examples of how I'd use mod_security in conjunction with mod_rewrite like the above example.
I intend to use something like this to handle POSTs:
RewriteCond %{REQUEST_URI} ^/somepath/somepath
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^/somepath/somepath(.*) /otherpath/otherpath [PT]
...except that I need a RewriteCond that inspects the POST parameters to see if "try=3".
Can modsecurity inspect the request body and load the result of that inspection in an environment variable? that would work...
Step 1 — Enabling mod_rewrite In order for Apache to understand rewrite rules, we first need to activate mod_rewrite . It's already installed, but it's disabled on a default Apache installation. Use the a2enmod command to enable the module: sudo a2enmod rewrite.
A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
You can't inspect the request body using mod_rewrite.
You may have to rewrite POST requests to a script if that's something that you can do. Browser's aren't always going to resend POST data if you redirect them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With