Create clean URLs using forms

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, the URL is currently returned like this:

 localhost/movie/index.php?search=ted 

I would like the url to return like this:

 localhost/movie/search/ted 

EDIT:

Now I 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 enter the URL /movie/search/ted , but when you submit the form, it still appears as /movie/index.php?search=ted

+1
php .htaccess mod-rewrite
source share
1 answer

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

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

+2
source share

All Articles