我的本地服务器的根目录是 /Users/myname/Sites ,所有 Web 项目都位于单独的目录中,例如 /Users/myname/Sites/newproject
我遇到的问题是我有一个包含所有 html 路径的网站以斜杠开头,例如
这使得浏览器在 /Users/myname/Sites/ 中查找文件 file.txt,而不是在文件所在的 /Users/myname/Sites/newproject。
我不是编辑每个文件路径来删除开头的斜杠或在开头放入 php 变量,而是想知道是否有一些简单的方法可以在整个站点范围内进行操作?
我尝试使用
我尝试在 .htaccess 中设置 DocumentRoot
我尝试设置 $_SERVER['DOCUMENT_ROOT '] 到 $_SERVER['DOCUMENT_ROOT']."/newproject";
不幸的是,这些似乎都不起作用。
The root of my local server is /Users/myname/Sites and all web projects are in seperate directories in that e.g. /Users/myname/Sites/newproject
The problem I've got is I've got a site which has all html paths written beginning with a slash e.g <a href="/dir/file.txt">
which makes the browser look for the file file.txt in /Users/myname/Sites/ rather than in /Users/myname/Sites/newproject where the file is located.
Rather than edit every single file path to either remove the beginning slash or to put in a php variable at the start I was wondering if there was some easy way to do this site wide?
I've tried using <base href="http://localhost/newproject" />
I've tried setting the DocumentRoot in .htaccess
I've tried setting the $_SERVER['DOCUMENT_ROOT'] to $_SERVER['DOCUMENT_ROOT']."/newproject";
Unfortunately none of these seem to work.
发布评论
评论(2)
您想要设置一个虚拟主机(如果您使用的是 apache)来指定 / url 应映射到 /User/myname/Sites/newproject。
您可以像这样执行此操作(编辑 httpd.conf 或在 conf.d 中放置一个文件):
请注意,当您执行此操作时,您本质上是“将文档根设置为您的新项目文件夹”,这将隐藏站点中的其他所有内容文件夹。
如果这不是您所说的,请告诉我,以便我修改我的答案。
You want to setup a virtual host (if you are using apache) to specify that the / url should map to /User/myname/Sites/newproject.
You would do this like so (edit httpd.conf or place a file in conf.d):
Note that when you do this, you are essentially "setting document root to be your newproject folder", which will shadow everything else in the Sites folder.
If this is not what you are talking about, please let me know so I can modify my answer.
您可以尝试设置虚拟主机。从您的文件夹结构假设您使用的是 Mac OS X,请尝试以下操作:
http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard
You can try setting up a virtual host. Assuming from your folder structure that you are on Mac OS X, try this:
http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard