How to hide URL from users when submitting this form?

I have a form with many fields ...

When sending these fields, I use the POST method, which hides the actual variables passed to the PHP page.

However, I cannot get rid of the full link.

Going from GET to POST made all form fields invisible in the URL , but this part is still visible:

mydomain.com/bin/query# 

I want it to be invisible, or say:

  mydomain.com/search 

I have mod_rewrite , so there is the option to do this with mod_rewrite I think, but I'm new to mod_rewrite , so I need your help ...

How do I hide this URL?

If you need more input let me know ...

+1
source share
5 answers

When sending from you, you must specify the action attribute for the form. I assume your action is mydomain.com/bin/query# , but you want it to be mydomain.com/search . Then you should use mydomain.com/search using the attitute action and rewrite the following:

 RewriteEngine on RewriteRule ^/search$ /bin/query [QSA,NC] 

This would display mydomain.com/serach in browser urls.

EDIT . Using the QSA flag, you can pass GET parameters to your script request. NC makes case-insensitive correspondence.

Your form should look like this:

 <form action="/search" method="post"> ... </form> 
+3
source

You do not have to hide the URL, it is a waste of time.

A user browser (which is under user control) sends data to your server. Users can always send any data they like to the form handler (since you cannot tell the browser where to send it without making this information available to the user). Using mod_rewrite just changes the URL (so there’s no benefit in hiding it), and search engines don’t process POST requests (so there’s no SEO benefit).

If you are looking for cosmetic benefits, then I'm really not worried about it. The number of users who would notice the URL of the submitted form is tiny, and the number of those concerned is even smaller.

+2
source

Suppose you are new to the world of the Internet, here are 2 rules for you:

  • According to the HTTP standard, searches should be performed using the GET method, not POST
  • Hiding URLs is nonsense. Although you can use mod_rewrite to decorate the URL rather than “hide” it.
  • Hiding search variables is nonsense, without excuses. the search should be done using the GET method, not POST
+2
source

Try RewriteRule ^/search /bin/query , then you can change the action of the form in / search

+1
source

What you can do is issue a redirect after processing your form.

 // process form vars eg, save_values($_POST); // redirect header('Location: /some/other/page'); exit; 

Browser users will only see the page you end up redirecting to. It will still be possible to check HTTP requests / responses to determine where the form is processed if you know what you are doing.

+1
source

Source: https://habr.com/ru/post/1312321/


All Articles