生成干净的URL使用表单时, [英] Generating clean URLs when using forms
问题描述
下面的形式:
<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>
当表单提交,目前该URL返回像这样:
When the form is submitted, currently the URL returns like so:
localhost/movie/index.php?search=ted
我想为URL回到像这样:
I would like for the URL to return like so:
localhost/movie/search/ted
编辑:
我现在有以下的code在我的.htaccess:
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]
当您在网址键入这工作/电影/搜索/特德
但是当你提交表单它仍然出来为 /电影/的index.php?搜索=特德
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
推荐答案
重写规则不更改URL,他们只是告诉你的服务器间preT网址属于统治之下 ^搜索/([A-ZA-Z0-9] +)/ $
如的index.php?搜索= $ 1
。
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
.
如果你想改变将要使用的链接,你必须在你的HTML改变它&LT;形式的行动=''
If you want to change the link that will be used, you have to change it in your html <form action=''
这篇关于生成干净的URL使用表单时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!