形式方法="获得" pretty的网址形式、网址、方法、QUOT

2023-09-02 00:59:00 作者:骨折旳蚯蚓

所以我用这个HTML表单一个简单的搜索框

So I'm using this HTML form for a simple search field

<form action = "/search/" method = "get">
<input type = "text" name = "search_term"/>
</form>

但是当它在URL处理是这样的

But then when it processes in the URL it's like this

http://mysite.com/search/?search_term=something

我知道这是完全正常的,但有一种方式来获得它来发送这样吗?

http://mysite.com/search/something

然后,我将使用的.htaccess中的搜索目录重写URL。

推荐答案

你想只是网址为pretty的或你想要的参数进行隐藏的网址。你可以改变你的方法='后',它会通过所有隐藏用户的参数作为HTTP头的一部分,彻底。如果你想使URL看起来更好,你应该看看mod_rewrite的和.htaccess文件如何从?SEARCH_TERMS =东西更改搜索查询 /某事

Do you want just the URL to be pretty or you want the parameters to be hidden from the URL. You can change your method='post' and it'll pass all the parameters as part of the HTTP Header and completely hidden from your user. If you want to make the URL look nicer, you should look at mod_rewrite and .htaccess files on how to change a search query from ?search_terms=something to /something