对 example.com/username 与路由的意见
我正在建立一个网站,用户有自己的“个人资料”。 我正在使用简洁 URL 的路由,我想知道以下内容的优点/缺点是什么:
example.com/:username
或者我应该包含一个静态路由来过滤它是个人资料页面请求吗?
example.com/u/:username
example.com/something-static/:username
哪个最好?
I'm setting up a site where users have their own "profile". I'm using routes for neat URLs and I wondered what are the pros/cons to the following:
example.com/:username
Or should I include a static route to filter that it's a profile page request?
example.com/u/:username
example.com/something-static/:username
Which is best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果用户可以指定他们的用户名并以显着的方式自定义他们的个人资料页面,那么您将面临遭受欺诈/网络钓鱼攻击的风险。
例如,我可以使用用户名“passwordreset”进行注册,然后在我的个人资料页面上放置一个表单(或表单的链接),然后尝试说服人们需要通过访问 example.com 来重置密码/重设密码。
然后我就可以获取密码了。
如果 URL 是 example.com/users/passwordreset,则警报用户更有可能变得可疑。
If it is possible for the user to specify their username and customize their profile page in a significant way, then you run the risk of enabling fraud/phishing attacks.
For example, I could register with a username of "passwordreset", and then put a form (or a link to a form) on my profile page, and then try to persuade people that they need to reset their passwords by visiting example.com/passwordreset.
Then I could harvest the passwords.
If the URL was example.com/users/passwordreset, there is more chance that an alert user would become suspicious.
我认为您不会想要,
因为这会对可用的用户名施加限制,以免与网址下的其他路径发生冲突。
我会建议
I don't think you'd want
as that would put restrictions on the usernames available so as not to clash with other paths under the url.
I would propose