.htaccess twitter 或 facebook URL 命名约定

发布于 2024-08-27 06:16:47 字数 236 浏览 6 评论 0原文

对于我的社交网站,我想构建一个 facebook 或 twitter 类似的 URL 重写命名约定。

以 Twitter 为例,他们的页面标记为 twitter.com/about ,另一个页面标记为 twitter.com/{$username}

但是,您如何区分在我们网站上注册为“about”的用户。由此,我们将在用户“about”和页面 about 之间发生服务器冲突。

处理这个问题的最佳方法是什么?

For my Social Networking Site, I would like to build a facebook, or twitter similar URL rewriting naming convention.

Using Twitter as an example, they have pages labeled twitter.com/about and another page labeled twitter.com/{$username}

However, how do you differentiate between say a user who has registers on to our site as "about" then. From this we are going to have a server conflict between the user "about" and the page about.

What is the best way to handle this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素食主义者 2024-09-03 06:16:47

通常,您会看到这一点已实现,因此不可能发生冲突。例如,您可以将所有用户驻留在虚拟 /users 目录或子域中:mysite.com/users/msilvisusers.mysite.com/msilvis

我不建议您让所有用户都可以通过站点的根目录进行访问,因为这可能会限制您添加页面。例如,假设您还没有“关于”页面,但用户注册并称自己为“关于”;你完蛋了。

如果您仍然选择这样做,请在注册之前尝试向您的网站发出 HTTP 请求,到达用户将拥有的页面。如果您没有收到 404 错误,则某些东西已经具有该名称。

Usually, you'll see this implemented so that conflicts are not possible. For instance, you could camp all users inside a virtual /users directory, or a subdomain: mysite.com/users/msilvis, or users.mysite.com/msilvis.

I would not recommend that you make all users accessible via the root directory of your site, because this could potentially restrain you from adding pages. For instance, suppose you do not have yet an "about" page, but a user registers and calls itself "about"; you're screwed.

If you still choose to do so, before registration, try an HTTP request to your website to the page the user would have. If you don't get a 404, then something already has that name.

吾性傲以野 2024-09-03 06:16:47

我们最终的决定是,在我们的服务器 mysite.com/user 上请求一个页面时,它首先检查这是否是一个页面,如果不是一个页面,它假设它是一个用户,其中在这种情况下,它会检查该用户是否是一个对象,如果不是,则会传递到我们的 404 页面。

因此,除此之外,我们将使用您之前提到的 HTTP 请求,然后,如果某些用户“about”仍然注册(我们现在有一个页面),那么他基本上就很糟糕,因为他不会看到他的页面。

What our final decision came down to, was upon requesting a page on our server mysite.com/user, it first checked to see if that was a page, if it IS NOT a page, it assumes that it is a user, in which case it checks to see if that user is an object, if it is not then it gets passed to our 404 page.

So ontop of this, we are going to use the HTTP request like you mentioned earlier, and then if some how user "about" still signs up which we now have a page for, essentially sucks to be him because he is not going to see his page.

九命猫 2024-09-03 06:16:47

我会限制某人创建与现有网址冲突的用户名的能力。

I would restrict the ability for someone to create a username that would conflict with existing urls.

柳絮泡泡 2024-09-03 06:16:47

如果您仍处于开发的早期阶段,您可以查看 Kohana PHP 框架。它的路由功能解决了 zneak 和 dd 强调的问题,您只需在路由中定义 http://yoursite.com/ about 将指向特定的控制器/操作,考虑到您想要一个像 twitter 一样的 url 结构,我假设您正在使用 MVC 设计模式。

希望有帮助!

编辑:我忘了提及,这并不会阻止人们注册,它只会阻止世界其他地方链接到该人的页面,为了防止他们,你需要使用某种针对您的核心页面(又名“关于”、“联系”等)进行验证。

If you're still in the early stages of development, you could look at the Kohana PHP framework. It's routing features solve the problem highlighted by zneak and dd, you would simply define in your routes that http://yoursite.com/about would point to a particular controller/action, i presume you're using the MVC design pattern considering you want a twitter like url structure.

Hope that helps!

EDIT: I forgot to mention that this doesn't stop people from signing up as about, it would just prevent the rest of the world from being linked to that persons page, in order to prevent them you'd need to employ some kind of validation against your core pages aka about, contact ect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文