Reputation: 87
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
Upvotes: 1
Views: 1249
Reputation: 3644
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=''
Upvotes: 2