0

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?

Jay
  • 4,994
  • 4
  • 28
  • 41
  • You would need to write a web application in your favorite language to handle those form posts and issue an appropriate redirect. Apache itself does not inspect the body of `POST` requests. – larsks Dec 03 '19 at 13:12
  • Can you maybe use `method = 'get'` to give Apache access to the form data? – jared Dec 09 '19 at 13:16
  • Is your `
    ` `method` attribute `GET` or `POST`? If not specified it is `GET`.
    – Marinos An Dec 09 '19 at 14:03
  • for action usually will be an url. Not a number – Akhil Surapuram Dec 09 '19 at 20:11
  • @Jay kindly look at this regarding formaction https://www.w3schools.com/tags/att_input_formaction.asp – Akhil Surapuram Dec 09 '19 at 20:14
  • is 5 and 5+ indicates your undefined nav options? – Akhil Surapuram Dec 09 '19 at 20:31
  • Sorry for missing these responses earlier, This form does a post:
    . There is also a hidden field in the form named "form_action". The navigation servlet determines where to direct the request based on the form value. However, I was hoping to have apache catch these requests, and direct the browser to some other place based on the logic I shared above. I wanted to pursue an apache redirect solution to avoid altering a very old application.
    – Jay Dec 09 '19 at 20:32
  • What does "is 5 and 5+ indicates your undefined nav options? " mean? – Jay Dec 09 '19 at 20:33
  • like 1-4 indicates your Nav options – Akhil Surapuram Dec 10 '19 at 06:03
  • I've made changes to my application so I no longer need an apache solution, However, if there is an answer to my question, it may be helpful to someone else. – Jay Dec 11 '19 at 12:47

2 Answers2

0

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]
Akhil Surapuram
  • 654
  • 1
  • 8
  • 22
0

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.

Alcaeus D
  • 258
  • 3
  • 18
  • The reason for my question was in the hopes of not altering the application, changing from a post to a get would alter the application in my case – Jay Dec 11 '19 at 12:44
  • In that case, try to use this as an answer: https://stackoverflow.com/questions/358263/is-it-possible-to-redirect-post-data – Alcaeus D Dec 12 '19 at 12:54