Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite only on GET

It's a longshot, but I'm hoping to find a simple workaround for a bizarre bug that only manifests when the query string is omitted/inferred by the application.

Before I dig deep into a thousand lines of minified 3rd party javascript, I'd like to find out if I can just auto apply the querystring using mod_rewrite.

RewriteRule    ^index\.php$  index.php?module=Home&action=index

Now, this would work fine except sometimes all the data will be POSTed so I need a RewriteCond so the rule will only fire on GET requests, and not POST requests.

Is this possible?

like image 533
Code Magician Avatar asked Nov 22 '11 06:11

Code Magician


2 Answers

I'd recommend being explicit and only firing the RewriteRule when the request method is GET, rather than whenever it's not POST as there are numerous other methods. So your rewrite condition could look like this:

RewriteCond %{REQUEST_METHOD}  =GET

RewriteRule    ^index\.php$  index.php?module=Home&action=index
like image 175
SimpleAnecdote Avatar answered Nov 06 '22 10:11

SimpleAnecdote


Add this condition...

RewriteCond %{REQUEST_METHOD} !POST

...to not match POST requests.

like image 42
alex Avatar answered Nov 06 '22 11:11

alex