Forum Moderators: phranque

Message Too Old, No Replies

Search form using get

example.com/search.php?keyword=widget to example.com/search/widget/

         

scraptoft

1:23 pm on Sep 12, 2007 (gmt 0)

10+ Year Member



I am not quite sure if this is a PHP question or apache - or either.

I am creating a small search form where a user can search a mysql database of widgets. I am using method="get" in my <form> which when submitted takes you to the following URI:

http://www.example.com/search.php?keyword=widget.

What I want is the form to direct the browser to the this URI instead.

http://www.example.com/search/widget/

Is this possible to achieve as the form is handling a variable to perform the mysql query later on.
i.e
SELECT * FROM table where widget='$keyword'

Regards,

jdMorgan

2:05 pm on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is actually both a PHP question and an Apache question; You have to make changes on both ends.

Change the links on the page to the 'friendly' URL-format. Users will click those new links, sending a request to your server. In order to serve content for those URLs (which don't resolve to 'real' files), you must then internally rewrite those requests to the proper script, with the keyword copied to the query string appended to the local URL-path of the script.

Further, you may wish to redirect direct client requests for the 'unfriendly' URLs back to the 'friendly' URLs, so that the 'unfriendly' ones will be removed from search engine listings. So, this can be up to a three-part process.

More info here [webmasterworld.com].

Jim

scraptoft

3:03 pm on Sep 12, 2007 (gmt 0)

10+ Year Member



I am not sure if I missed it in your relpy Jim but my main problem is once the submit button is pressed the user is directed to http://www.example.com/search.php?keyword=widget.

I understand briefly how mod_rewrite works but as I understand mod_rewrite cannot change URI's therefore my main priorty is getting the submit button to direct the user to http://www.example.com/search/widget/.

Thank you for your time

scraptoft

12:44 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



Anyone else have some light to shed on this?

Cheers

jdMorgan

1:12 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> getting the submit button to direct the user to http://www.example.com/search/widget/.

Since the question isn't very focused, I'll just suggest that you'd do this by modifying the URL used by the POST action in the HTML form ("Submit" activates the "POST" action).

The URLs on/in your pages define the URLs seen by the client, and mod_rewrite can't change them. All it can do is to internally rewrite a URL, when received in an HTTP request from the client, to a non-default filepath within the server, or to externally redirect it to another URL -- an action which is visible to the client (and user), and in which the client must take action to complete.

Jim