skip to Main Content

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


  1. 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

    RewriteEngine on
    RewriteRule    "^/5"  "/navigation" [PT]
    

    for External reDirect

    RewriteEngine on
    RewriteRule    "^/5"  "/navigation" [R]
    
    Login or Signup to reply.
  2. 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 a RewriteRule to check the parameters value.

    i.e.:

    <form method="get" action="/nagivation">
      <input type="text" name="form_action" value=""> <!-- Your 'form_action' input -->
      <input type="submit" value="Submit"> <!-- Your submit button -->
    </form>
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search