1

Here is the form:

<form action='<?php echo $_SERVER['PHP_SELF'];?>'>
  <p><label>Movie Title:</label><input type='text' name='search'></p>
  <p><input id="submit" type='submit' value='Submit'></p>
</form>

When the form is submitted, currently the URL returns like so:

localhost/movie/index.php?search=ted

I would like for the URL to return like so:

localhost/movie/search/ted

EDIT:

I now have the following code in my .htaccess:

RewriteCond %{QUERY_STRING} ^search=(.*)$ [NC]
RewriteRule ^$ /search/%1 [NC,R,L] 
RewriteRule ^search/(.+)$ index.php?search=$1 [NC,L]

This works when you type in the URL /movie/search/ted but when you submit the form it still comes out as /movie/index.php?search=ted

CraigColes
  • 77
  • 10

1 Answers1

2

rewrite rules don't change the url, they just tell your server to interpret url that falls under the rule ^search/([a-zA-Z0-9]+)/$ like index.php?search=$1.

If you want to change the link that will be used, you have to change it in your html <form action=''

Darvex
  • 3,624
  • 2
  • 23
  • 39
  • How would I go about doing that, as I have tested a lot of possibilities and still not got the desired result. – CraigColes Jul 14 '12 at 18:26
  • this answer [here](http://stackoverflow.com/questions/5464481/clean-urls-for-search-query) should help you with that – Darvex Jul 14 '12 at 18:38
  • The only URL I can seem to get is: `localhost/movie/search/?search=ted` everything else I have tried either seems to cause a redirect loop or just fails completely. – CraigColes Jul 14 '12 at 18:50