Suggest best URL style

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 17:56:10

问题


Our system

Our search module can have many parameters like

  • search keyword
  • examination filter
  • subject filter
  • date range filter
  • course name filter ... ... etc

and there are pagination and sorting parameters like

  • Page number
  • Number of results in a page
  • sort field
  • sort order

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>

.... ... ...

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

Current Problem

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.

My Question

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. Having all the URL parameters present in all URLs, regardless of whether they are needed or not, like :-

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

    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

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

    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...

    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.

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

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

Thanks


回答1:


In Zend Framework, the Request object allows to pass data in any order and eventually use Router or Url View helper to create the page url in the way you wish at the moment.

This is the best pattern I know. No .htaccess rules at all.




回答2:


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?



来源:https://stackoverflow.com/questions/3218130/suggest-best-url-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!