生成干净的URL使用表单时, [英] Generating clean URLs when using forms

查看:117
本文介绍了生成干净的URL使用表单时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的形式:

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆