URL Slug:重定向还是 404?
有些网站(例如 SO)允许在 URL 中使用“虚假”别名。在我的网站上实现 URL slug 之前,我有一个“最佳实践”问题...
给定一个像 example.com/123/article-slug-here/
这样的结构,如果我的网站允许伪造的 slugs通过查询 ID -
我应该...
- 只是重定向到适当/规范的 URL(验证 slug,并在不匹配的情况下重定向)?
- 或 -
- 返回 404,因为从技术上讲
example.com/123/this-article-sux
不存在?
Some sites, like here at SO, allow 'bogus' slugs in the URL. Before implementing URL slugs on my site, I have a question of 'best practices'...
Given a structure like example.com/123/article-slug-here/
, if my site allows bogus slugs by querying on the ID -
Should I ...
- just do a redirect to the appropriate/canonical URL (verifying the slug, and redirecting in case of a mismatch)?
-or-
- return a 404, since technically
example.com/123/this-article-s-u-x
doesn't exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两者都不。保持原样。谷歌将找出规范的网址并将其保留在索引中。
仅当您希望让 Google 更快地更新其索引中已更改的网址时,您才可以进行重定向(当然是 301 永久移动)。如果不重要的话,就没必要打扰。
PS 我基本上在我的博客中做了同样的事情。有一次我更改了某些条目的标题,一段时间(几周)后,Google 根据页面中指定的新规范 URL 更新了他们的索引。简单又有效。
Neither. Leave it as it is. Google will figure out the canonical url and keep them in their index.
You could do redirect (301 Moved Permanently of course) only if you wish to punch Google to update the changed url in their index more quickly. If it's not important, no need to bother.
P.S. I basically did the same thing in my blog. Once I changed the title of some entry and after a while (a few weeks) Google updated their index in accordance to the new canonical url that was specified in the page. Simple and works.