Aptana Studio 3绝对路径预览问题

问题描述:

我的项目具有以下结构:

I have this structure for my project:

Root Directory
|-css folder
  |-style.css
|
|-it folder
  |-index.html

如果我尝试将CS​​S文件包含在以下内容中:

If I try to include css file with:

<link href="/css/style.css" rel="stylesheet" type="text/css"/>

从index.html,aptana预览以及内部服务器无法找到style.css. 为什么是这样? 在我的远程服务器中,它可以完美运行,并且我不想使用相对路径.

from index.html, aptana preview and also internal server can not find style.css. Why is this? In my remote server it works perfectly and I do not want to use a relative path.

就为什么"而言,您遇到的问题与开发服务器的设置与生产服务器的设置有关.

In terms of the "why", the problem you are having is related to how your development server is setup versus your production server.

假设使用标准设置,您的生产服务器将收到对域的请求(即 http://mysite.com ),也就是说,由于缺少更好的用词,因此映射到您服务器上的文件夹(即对 http://mysite.com的请求将被映射到服务器上的/var/www/mysite文件夹).

Assuming a standard setup, your production server will receive requests for a domain (i.e., http://mysite.com) that is, for lack of a better word, mapped to a folder on your server (i.e, a request to http://mysite.com will be mapped to a folder, /var/www/mysite, on your server).

因此,当您使用/css/style.css链接到样式表时,(生产)服务器将立即转到/var/www/mysite文件夹,并开始查找css文件夹,文件等.如您所指出的那样,这没有问题.

So, when you link to a style sheet with /css/style.css, your (production) sever immediately goes to the /var/www/mysite folder and starts looking for the css folder, file and so on. No problems with that, as you point out.

但是,您的开发机器正在本地提供页面,并且具有用于映射到文件和文件夹的不同目录结构.

Your development machine, however, is serving up pages locally and has a different directory structure for mapping to files and folders.

当我在Aptana项目中打开HTML页面并点击预览按钮时,Studio会加载 http://127.0.0.1:8020/mysite/public/404.html (请注意IP和端口之后的第一个文件夹是mysite).要加载绝对路径的CSS文件,本地服务器实际上正在寻找 http://127.0.0.1: 8020/css/styles.css ,但需要访问 http://127.0.0.1:8020/mysite/css/styles.css .

When I open an HTML page in my Aptana project and hit the preview button, Studio loads http://127.0.0.1:8020/mysite/public/404.html (note how the first folder after the IP and port is mysite). To load the absolutely pathed CSS file, the local server is actually looking for http://127.0.0.1:8020/css/styles.css but it needs to get to http://127.0.0.1:8020/mysite/css/styles.css.

链接(/css/styles.css)中的初始"/"告诉服务器进入服务器的根目录,并从该位置开始查找文件夹和文件...但是没有CSS本地服务器的根目录中的文件夹.它位于/mysite/css/styles.css中,这就是为什么fskreuz建议使用相对路径并使用"../css/styles.css"的原因.

The initial "/" in your link (/css/styles.css) tells the server to go to the root directory of the server and start looking for the folder and files from that point ... but there is no css folder in the local server's root directory. It lives in /mysite/css/styles.css and that's why fskreuz suggests relative paths and using "../css/styles.css" instead.

我个人而言,我更喜欢绝对链接(但这只是个人喜好,绝不是对fskreuz的回应的挑战或评论).但是,我的本地开发设置有利于使用它们,因为我为工作的站点设置了虚拟主机.使用Apache,我为每个项目设置了一个虚拟主机.这样,我可以在计算机上的任何浏览器中加载 http://dev.mysite.com 之类的内容并进行测试我的网站/应用的方式可以反映我的生产设置.

Personally, I prefer absolute links (but that's just a personal preference and not in any way a challenge to or comment upon fskreuz's response). However, my local development setup is conducive to using them because I setup virtual hosts for the sites I work on. Using Apache, I setup a virtual host for each of my projects. With this, I can load something like http://dev.mysite.com in any browser on my computer and test my site/app in a way that makes it mirror my production setup.