简体   繁体   English

清理URL

[英]Cleaning up URL

I installed friendly_id to clean up the model urls but I have a search function on my site and I'm not sure how to best clean that up. 我安装了friendly_id来清理模型URL,但是我的网站上有搜索功能,并且不确定如何最好地清理它。 This is what my search url looks like: 这是我的搜索网址:

http://localhost:3000/s?utf8=%E2%9C%93&s%5Blocation%5D=Paris%2C+France&s%5Bactivity%5D=6&s%5Bstart_time%5D=Aug+3rd+2015%2C+3%3A00+am&s%5Bend_time%5D=Aug+17th+2015%2C+4%3A00+am&s%5Bgeo%5D=%5B48.856614%2C2.3522219000000177%5D

Wondering if there's anything I can do since search isn't associated with a model so I can't use friendly_id. 想知道是否有什么我可以做的,因为搜索没有与模型相关联,所以我不能使用friendly_id。

"Cleaning" a search URL is definitely tricky. “清理”搜索URL绝对是棘手的。 Search parameters can contain spaces or other characters, including slashes, that may conflict with the Rails routing or even the URI RFC specification. 搜索参数可以包含空格或其他字符(包括斜杠),它们可能与Rails路由甚至URI RFC规范冲突。

That's why trying to achieve friendly URLs for search parameters is a waste of time. 因此,尝试为搜索参数获得友好的URL会浪费时间。 There is not even a real need for that. 甚至没有真正的需要。

Friendly URLs are generally useful in terms of user readability and marketing (eg SEO). 友好的URL通常在用户可读性和市场营销(例如SEO)方面很有用。 None of these advantages generally applies to a search form. 这些优势通常都不适用于搜索表单。

A quick option could be to change the search form from using GET parameters to POST (but you will lose the ability to pass a search link to someone else). 一种快速的选择是将搜索形式从使用GET参数更改为POST(但是您将无法将搜索链接传递给其他人)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM