Search code examples
phpurlsearchsearch-engine

Change URL for when this form is processed


I have a form that has no action attribute, a method of get, and a single input field of type text with a name of q.

When one enters 'query' and submits the form, the URL of the confirmation page looks like http://mySite.com/search.php?q=query.

How can I get the URL to be http://mySite.com/search?q=query

And for multi-word searches (like for 'query one') http://mySite.com/search?q=query+one ?

All while still navigating to the confirmation / results page.

How can I do this? I would prefer a solution not involving .htacess


Solution

  • Write the following code in your htaccess file

    RewriteEngine On
    RewriteRule ^search\?q\=([^/]*)$ /search.php?q=$1 [L]
    

    and then use http://mySite.com/search as action file in your form