I'm working a digg clone in ASP.NET MVC to help better teach myself ASP.NET MVC. I've been looking at how * handles routing when passing in things like sorts and I guess I thought the whole point of using clean URLs is so you don't have things like ?sort=blah at the end of your URL for SEO.
我在ASP.NET MVC中使用digg克隆来帮助更好地自学ASP.NET MVC。我一直在研究*在传递类似的东西时如何处理路由,我想我认为使用干净的URL的全部意义在于你没有类似的东西?在你的SEO结尾处有一些排序。
Is there a recommended way of including many, possibly optional parameters into your URLs whilst still keeping them clean. I had a few ideas and I'd like to get some feedback.
是否建议在URL中包含许多可能的可选参数,同时保持其清洁。我有一些想法,我想得到一些反馈。
Option 1:
Use wildcards (yuck)
使用通配符(yuck)
Option 2:
Add the sorting to the beginning of the URL since it has the greatest coverage and ALWAYS applies when viewing stories. Exampke (using *)
将排序添加到URL的开头,因为它具有最大的覆盖率,并且在查看故事时始终适用。 Exampke(使用*)
Instead of having ?sort=featured...
而不是?sort = featured ...
https://*.com/featured/tagged/asp.net-mvc
https://*.com/new/tagged/c#
https://*.com/tagged/asp.net (some sort of default)
https://*.com/featured/tagged/asp.net-mvc https://*.com/new/tagged/c# https://*.com/tagged/asp.net(某种默认值)
Anyway -- I can't seem to think of any other ways of doing this.
无论如何 - 我似乎无法想到其他任何方式。
3 个解决方案
#1
Hang on, stack overflow does use query string parameters for sort, e.g.:
挂起,堆栈溢出确实使用查询字符串参数进行排序,例如:
https://*.com/questions/518812?sort=oldest#sort-top
/featured is different. In this case you are controlling what records are returned, not just how their sorted.
/特色是不同的。在这种情况下,您将控制返回的记录,而不仅仅是它们的排序方式。
URLs describe resources. Query string parameters described how the resources are presented. In general:
URL描述资源。查询字符串参数描述了资源的呈现方式。一般来说:
- Fragments which describe the nature of the data returned should be part of the URL.
- Fragments which describe how that data is presented should be query string parameters.
描述返回数据性质的碎片应该是URL的一部分。
描述如何呈现数据的片段应该是查询字符串参数。
Having query string parameters will not hurt your SEO.
拥有查询字符串参数不会伤害您的SEO。
#2
You should go with a method that works best for you. Some things to consider:
你应该采用最适合你的方法。有些事情需要考虑:
- maintainability: how will you maintain the link structure over the lifetime. How will someone else?
- readability/debugging: How will you debug the links? Would natural language help you? (it helps me).
可维护性:如何在整个生命周期内维护链接结构。别人怎么样?
可读性/调试:如何调试链接?自然语言对你有帮助吗? (它帮助到我)。
#3
Let's say you have a controller called StoryController which shows all your posts. You can make your routes look like this:
假设您有一个名为StoryController的控制器,它会显示您的所有帖子。您可以使您的路线看起来像这样:
routes.MapRoute("FeatureTagged", "feature/tagged/{tag}", new {
controller = "Story", action = "ShowFeaturedByTag" });
routes.MapRoute("NewTagged", "new/tagged/{tag}", new {
controller = "Story", action = "ShowNewByTag" });
BTW, there's an ASP.NET MVC clone of digg already. It's called Kigg: http://www.codeplex.com/Kigg and it's being run on a site called DotNetShoutout
顺便说一下,已经有一个关于digg的ASP.NET MVC克隆了。它被称为Kigg:http://www.codeplex.com/Kigg,它正在一个名为DotNetShoutout的网站上运行
#1
Hang on, stack overflow does use query string parameters for sort, e.g.:
挂起,堆栈溢出确实使用查询字符串参数进行排序,例如:
https://*.com/questions/518812?sort=oldest#sort-top
/featured is different. In this case you are controlling what records are returned, not just how their sorted.
/特色是不同的。在这种情况下,您将控制返回的记录,而不仅仅是它们的排序方式。
URLs describe resources. Query string parameters described how the resources are presented. In general:
URL描述资源。查询字符串参数描述了资源的呈现方式。一般来说:
- Fragments which describe the nature of the data returned should be part of the URL.
- Fragments which describe how that data is presented should be query string parameters.
描述返回数据性质的碎片应该是URL的一部分。
描述如何呈现数据的片段应该是查询字符串参数。
Having query string parameters will not hurt your SEO.
拥有查询字符串参数不会伤害您的SEO。
#2
You should go with a method that works best for you. Some things to consider:
你应该采用最适合你的方法。有些事情需要考虑:
- maintainability: how will you maintain the link structure over the lifetime. How will someone else?
- readability/debugging: How will you debug the links? Would natural language help you? (it helps me).
可维护性:如何在整个生命周期内维护链接结构。别人怎么样?
可读性/调试:如何调试链接?自然语言对你有帮助吗? (它帮助到我)。
#3
Let's say you have a controller called StoryController which shows all your posts. You can make your routes look like this:
假设您有一个名为StoryController的控制器,它会显示您的所有帖子。您可以使您的路线看起来像这样:
routes.MapRoute("FeatureTagged", "feature/tagged/{tag}", new {
controller = "Story", action = "ShowFeaturedByTag" });
routes.MapRoute("NewTagged", "new/tagged/{tag}", new {
controller = "Story", action = "ShowNewByTag" });
BTW, there's an ASP.NET MVC clone of digg already. It's called Kigg: http://www.codeplex.com/Kigg and it's being run on a site called DotNetShoutout
顺便说一下,已经有一个关于digg的ASP.NET MVC克隆了。它被称为Kigg:http://www.codeplex.com/Kigg,它正在一个名为DotNetShoutout的网站上运行