How to hide URL from users when submitting this form?
I have a form with many many fields...
When submitting these fields, I use the POST method which hides the actual variables passed along to the PHP page.
However, I can't get rid of the complete link.
Changing from GET to POST did make all the 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
enabled so there is a p开发者_开发技巧ossibility to do this with mod_rewrite
I think, but I am new to mod_rewrite
so I need your help...
How should I hide this URL?
If you need more input let me know...
When submitting a from you have to specify a action attribute for the form. I assume that your action is mydomain.com/bin/query#
but you want it to be mydomain.com/search
. Then you should use mydomain.com/search
withing the action attibute and the following rewrite:
RewriteEngine on
RewriteRule ^/search$ /bin/query [QSA,NC]
That would show mydomain.com/serach
in the browsers URL.
EDIT: Using the QSA flag you can pass GET paremeters to your query script. The NC makes the rewrite case-insensitive.
Your form should look like this:
<form action="/search" method="post">
...
</form>
You shouldn't hide the URL, it is a waste of time.
The user's browser (which is under the control of the user) sends data to your server. Users will always be able to send whatever data they like to the form handler (since you can't tell the browser where to send it without making that information available to the user). Using mod_rewrite just changes the URL (so there is no security benefit from hiding it) and search engines don't make POST requests (so there is no SEO benefit).
If you are looking for a cosmetic benefit, then I really wouldn't worry about it. The number of users who would notice the URL the form submitted to is tiny, and the number who care is even smaller.
Supposing you're new in the web world, here is 2 rules for you to learn:
- According to HTTP standard, search must be done using GET method, not POST
- Hiding url is a nonsense. Though you can use mod_rewrite to beautify the URL, not to "hide" it.
- Hiding search variables is a nonsense, with no excuses. search must be done using GET method, not POST
Try RewriteRule ^/search /bin/query
then you can change your form action to /search
What you can do is issue a redirect following your form processing.
// process form vars e.g.,
save_values($_POST);
// redirect
header('Location: /some/other/page');
exit;
Browser users will only see the page you eventually redirect too. It will still be possible to inspect the HTTP requests/responses to determine the location of the form processing if you know what you're doing.
精彩评论