域屏蔽/指向 Web 应用程序的目录? [英] Domain masking/pointing to a directory of a web application?
问题描述
我构建了一个 LAMP 网络应用程序,让用户可以创建他们自己的个人资料页面,他们可以在其中上传他们的简历和作品集.一个人的个人资料的网址将类似于
I built a LAMP web application that let's users create their own profile page where they can upload their resume and portfolio. The url for a person's profile will be something like
http://jobbank.com/user/johndoe
John Doe 注册了域名 http://johndoefreelancer.com 并且他希望它指向 http://jobbank.com/user/johndoe.任何访问 johndoefreelancer.com 的人都不应该意识到它是由 http://jobbank.com/user/johndoe<驱动的/a>.这意味着浏览器 url 应该持续显示地址,例如:
John Doe registers the domain name http://johndoefreelancer.com and he wants it to point to http://jobbank.com/user/johndoe. Anyone who visits johndoefreelancer.com should not be aware that it's driven by http://jobbank.com/user/johndoe. This means that the browser url should persistently show addresses such as:
http://johndoefreelancer.com/aboutme(真的指向jobbank.com/user/johndoe/关于我)http://johndoefreelancer.com/portfolio(真正指向jobbank.com/user/johndoe/portfolio)
http://johndoefreelancer.com/aboutme (really points to jobbank.com/user/johndoe/aboutme) http://johndoefreelancer.com/portfolio (really points to jobbank.com/user/johndoe/portfolio)
此外,点击任何链接 [a href=""] 应该让您留在 johndoefreelancer.com,而不是将您转到 jobbank.com.
Additionally, clicking on any links [a href=""] should keep you at johndoefreelancer.com instead of sending you to jobbank.com.
我的问题是,实现这一目标的最佳方法是什么?
My question is, what is the best way to achieve this?
我正在考虑:1) 向用户说明如何使用掩码进行域转发
I'm considering: 1) Give instructions to users on how to domain forward with masking
2) 指导用户填写其用户资料信息中的$homeUrl字段,该字段已保存到数据库中
2) Instruct users to fillout the field $homeUrl in their User Profile information, which is saved to the database
3) 在我的 PHP 代码中,如果 $homeUrl 存在,将所有 [a href="$_SERVER['HTTP_HOST']"] 替换为 [a href="$homeUrl"]
3) In my PHP code, if $homeUrl exists, replace all [a href="$_SERVER['HTTP_HOST']"] with [a href="$homeUrl"]
这是正确的方法吗?有没有更好的办法?
Is this the right approach? Is there a better way?
推荐答案
另一种方法是告诉您的用户将他们的域指向您的 IP,并将它们设置为基于名称的虚拟主机.好处是:
An alternative approach would be to tell your users to point their domains to your IP and set them up as name-based virtual hosts. The benefits are:
- 用户设置然后转发掩码要容易得多(后者甚至可能无法实现,具体取决于注册商)
- 您不必在 PHP 代码中处理 URL 重写.
如果您不必为 URL 使用 /user/johndoe
前缀(您实际上并不需要这样做,因为您可以在代码中进行域查找),这将更容易设置以确定用户 ID),但也可以使用前缀 - 只是在这种情况下必须更多地参与 mod_rewrite 设置(您需要为每个域进行设置).
This would be easier to setup if you did not have to use /user/johndoe
prefix for your URLs (which you don't really need to because you can do a domain lookup in your code to determine user id), but is possible with the prefix as well - it's just that mod_rewrite setup would have to be more involved in that case (you'll need to do it per domain).
这篇关于域屏蔽/指向 Web 应用程序的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!