Aptana Studio 3 的绝对路径预览问题 [英] Aptana Studio 3 preview problems with absolute path

查看:26
本文介绍了Aptana Studio 3 的绝对路径预览问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有这样的结构:

I have this structure for my project:

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

如果我尝试包含 css 文件:

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.

这篇关于Aptana Studio 3 的绝对路径预览问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆