Forum Moderators: open

Message Too Old, No Replies

Forms - directing the browser to specific url.

Without the question mark and equals sign.

         

scraptoft

1:18 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



<FORM ACTION="http://www.example.com/search/" METHOD=GET>
<INPUT TYPE=submit NAME=foo VALUE="keyword">
</FORM>

This form directs the brwoser to:
example.com/search/?foo=keyword.

Is it possible to direct the browser to:
example.com/search/foo/keyword instead?

Notice I don't want the '?' or '=' in the url.

Does anyone know how (if) I can achieve this? If no is there an alternative?

I can't find the answer anywhere so I am begining to think it is impossible, which would be a shame.

Regards,

phranque

1:56 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



for one thing, you can prevent the form parameters from showing in the resulting url if you use METHOD=POST instead.

the answer to your question has two parts.
first, you should send an external redirect that the browser can use to request your preferred url.
then your server should be set up to handle the preferred url, either with documents in a directory structure matching the url path or using internal rewrites to resolvable urls.

scraptoft

2:39 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Hi phranque thanks for replying.

I am not using the POST method as I would like the user to have the url. (As a resource or so)

Could you explain more about sending an external redirect that the browser can use to request your preferred url. That went a bit over my head, sorry ;-).

I am currently using mod_rewrite to handle the directory type structure. My thinking is that once the form directs the browser to the URL I want mod_rewrite should be handle it.

phranque

2:53 pm on Sep 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you could send a document which contains a Location header:

Location:http://example.com/search/foo/keyword

scraptoft

5:54 pm on Sep 20, 2007 (gmt 0)

10+ Year Member



Ok, i've got it to work great.

my form ACTION is now set to test.php (show below).

<?php
header("Location: http://example.com/$foo"); /* Redirect browser */
exit;
?>

This then directs the browser to example.com/keyword.

Is this the standard way of doing this?

p.s Thank you for your time and help phranque, grealty appreciated.