Aptana Studio 3 preview problems with absolute path

我们两清 提交于 2019-12-14 01:24:20

问题


I have this structure for my project:

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

If I try to include css file with:

<link href="/css/style.css" rel="stylesheet" type="text/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.


回答1:


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

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).

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.

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.

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.

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.



来源:https://stackoverflow.com/questions/8669664/aptana-studio-3-preview-problems-with-absolute-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!