相对地址和绝对地址
我的问题涉及相对和绝对地址。
多年来我构建了一个框架,我所有的 php 网站都构建在该框架上。
每个页面都加载到顶级“index.php”文件中。 这很酷,因为我从不为获取资源的路径而苦苦挣扎。系统每个级别的每个资源都是从顶级索引文件引用的,因此路径始终相似:
ie (img src="images/sprites/xxxxx.jpg" ) 来自系统中的每个页面。
但现在我通过引入 mod_rewrite 毁了它。 mod rewrite 似乎混淆了我一直在使用的路径系统。所以是时候更新路径了。样式表和图像不再加载。
我应该如何解决这个问题?相对路径的加载速度真的比绝对路径快吗? PHP 中是否有某种方法可以找到服务器文件系统的根目录并将其分配给 $var,然后将该 $var 添加到图像路径?这比仅仅引用我的图像和内容更快吗?样式表为“http://site.com/images/xxxx.jpg”?
我现在有很多东西要学。请输入任何内容
My question regards relative and absolute addresses.
I have over the years built a framework, which all my php websites are built on.
Every single page is loaded in the top level "index.php" file.
This is cool, because I never struggle with paths to resources. Every single resource, at every single level of the system is referenced from the top level index file, so the paths are always similar:
ie (img src="images/sprites/xxxxx.jpg" )
from every single page in the system.
But now I've ruined it by introducing mod_rewrite.
mod rewrite seems to have confused the path system I've been using. So it's time for me to update the paths. Stylesheets and images no longer load.
How should I fix this? Is it true that relative paths are loaded faster than absolute?
isn't there some way in PHP to find the root of your server file system assign it to a $var and then prepend that $var to image paths? Is that any faster than just referencing my images & Stylesheets as "http://site.com/images/xxxx.jpg" ?
I have alot to learn now. Any input please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以
/
开头的 URI,以便它们相对于当前域的根(保持相同的协议和端口)。它们更短,因此节省了一些字节,所以从技术上来说——是的。但这并不是一个显着的节省。
是的,但是上面的技术更简单。
Use URIs that start with a
/
so they are relative to the root of the current domain (keeping the same protocol and port).They are shorter, so they save a few bytes, so technically — yes. This isn't a significant saving though.
Yes, but the above technique is simpler.
只需在
images
目录之前添加一个/
即可,其效果与以下内容相同:
Just add a
/
before theimages
directoryit's the same as:
$_SERVER["DOCUMENT_ROOT"]
将会满足您的要求:但我同意其他发帖人的观点,即根相对路径(前导斜杠)是一个更简单的解决方案。
$_SERVER["DOCUMENT_ROOT"]
will get you what you asked for:But I agree with the other posters that root relative (leading slash) paths is a simpler solution.