建议最佳 URL 样式 [英] Suggest best URL style

查看:20
本文介绍了建议最佳 URL 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的系统

我们的搜索模块可以有很多参数,比如

Our search module can have many parameters like

  • 搜索关键字
  • 考试过滤器
  • 主题过滤器
  • 日期范围过滤器
  • 课程名称过滤器......等

还有像

  • 页码
  • 页面中的结果数
  • 排序字段
  • 排序顺序

我们曾经有这样的网址:-

We used to have URLs like:-

www.projectname/module/search/<search keyword>/<examination filter>/<subject filter>/
www.projectname/module/search/<search keyword>/<examination filter>/<subject filter>/<Page number>,<Number of results in a page>,<sort field>,<sort order>

..........

我们在 htaccess 中对每个变体都有一个重写规则.

And we were having one rewrite rule in htaccess for every variation.

当前问题

由于多个 URL 的麻烦导致代码维护出现问题,我现在求助于 PHP 函数来完成任务,而不是 htaccess,类似于 Zend、Codeignitor 等框架的 URL 库.

Because of the trouble of multiple URLs causing problems in maintenance of code, I am now resorting to PHP functions to do the task instead of htaccess, something similar to URL libraries of frameworks like Zend, Codeignitor.

我的问题

考虑到并非每次都需要所有搜索过滤器/parmas,我只想就以下哪种 URL 格式约定更好地遵循一些建议.那么,最好遵循以下 2 个约定中的哪一个:-

I just want some suggestions on which of the following conventions of URL format is better to follow considering the fact that all the search filters/parmas will not be needed everytime. So, which of the following 2 conventions are better to follow:-

  1. 在所有 URL 中包含所有 URL 参数,无论是否需要它们,例如:-

  1. Having all the URL parameters present in all URLs, regardless of whether they are needed or not, like :-

www.projectname/module/search/hello//110/...所有其他参数存在...

www.projectname/module/search/hello//110/...all other params present...

这里我们不用说哪个参数是搜索关键字,哪个是主题过滤器.一个简单的 URL 解析器函数总是假定来自 www.projectname/module/的第二个参数作为搜索关键字(在本例中为 hello),其他参数也类似.在这个例子中,考试过滤器不适用,所以它留空,它不会破坏 URL,但它很好.如果有很多空白参数,那么会出现很多背对背斜线

Here we do not need to mention that the which param is search keyword and which one is subject filter. A simple URL parser functions always assumes the 2nd param from www.projectname/module/ as the search keyword (hello in this case) and similarly for other params. In this example exam filter is not applicable and so it is left blank and it does not break URL but is it nice. If there were many blank params then there will appear many back to back slashes

允许以任何顺序自由传递 URL 参数,如下所示:-

Allowing freedom to pass URL params in any order like this:-

www.projectname/module/search/search_keyword/hello/subject_filter/110/...其他需要的参数只存在...www.projectname/module/search/subject_filter/110/search_keyword/hello/...其他需要的参数只存在...

www.projectname/module/search/search_keyword/hello/subject_filter/110/...other needed params only present... www.projectname/module/search/subject_filter/110/search_keyword/hello/...other needed params only present...

这两个网址的意思相同在此约定中,URL 解析器函数解析每个名称-值对,并将名称search_keyword"旁边的值作为搜索关键字,其他类似(在此示例中名称 = search_keyword,值 = hello).该函数将解析每个名称值对,因此作为其他对的值出现的术语 search_keyword 不会干扰.

Both of these URLs mean the same In this convention, the URL parser function parses every name-value pair and takes the value next to name "search_keyword" as the search keyword and similarly for others (in this example name = search_keyword, value = hello). The function will parse each every name value pair and so the term search_keyword appearing as value for some other pair will not interfere.

建议时请考虑以下因素:-- SEO友好- 易于维护(考虑到未来可能会添加新过滤器)

Please consider the following factors while suggesting:- - SEO friendliness - ease of maintainability (considering new filters may be added in future)

请提供一些有关提高 SEO 友好度的提示.我对此知之甚少

Please give some tips on improving SEO friendliness. I have little knowledge on that

谢谢

推荐答案

我自己选择了最好的解决方案.我觉得第二个约定,即 允许以任何顺序自由传递 URL 参数 更好,因为如果在某些情况下不传递一个或多个参数,第一个约定可能会导致背对背斜线.要了解更多关于为什么我们应该避免不必要的背对背斜杠检查 为什么我们不这样做不使用此类 URL 格式?

I have chosen the best solution myself. I feel the 2nd convention , i.e. Allowing freedom to pass URL params in any order is better only because the 1st convention may result into back to back slashes if one or more parameters are not to be passed in some case. To read more on why we should avoid unnecessary back to back slashes check Why we don’t use such URL formats?

这篇关于建议最佳 URL 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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