I have an old web application that is fronted with Apache/2.2.34. I plan on using RewriteEngine and RewriteRule to redirect some requests without updating the application. However, one of the rules I need is dependent based off of form values. For example, I want to redirect “/navigation” to “some place else” only when the form element “form_action” is equal to 5. Is there a way to do this in Apache?
2
Answers
Form action values are urls may be absolute urls or relative.
Not Sure of the Exact reWrite rule but wrote based on other rewrite examples
for internal reDirect
for External reDirect
Maybe the best thing that could fix your problem is to send the data over
GET request
. The reason for doing this is that you can pass the form’s inputs as URL parameters and then create aRewriteRule
to check the parameters value.i.e.:
The above form, will send its data to
https://www.example.com/nagivation?form_action=5
only if the user fills the input with the value of ‘5’ and submits the form. Also, you will see the URL in your browser changing to the one I provided.so, if your
RewriteRule
catches the/navigation?form_action=5
you can succesfully do the redirect.Check this example for better understanding
Finally, here you can see how to add a RewriteRule using URL parameters.