在非根位置绝对路径部署 [英] Absolute Path for Deployment in a Non-Root Location

查看:141
本文介绍了在非根位置绝对路径部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用通常是指任何资产在我的网站的绝对路径的,这样我就不必担心相对于当前文件的资产的位置。

I typically refer to any assets on my site using absolute path so that I don't have to worry about the location of the assets relative to current file.

<!-- Using a absolute path. -->
<img src="/images/flag.png" />
<!-- Using a relative path. -->
<img src="../../../images/flag.png" />

不过,这一次,我需要在非根位置例如主办的网站 http://my-server.com/holiday/

我会如何呢?我找的,不需要我改变我的文件的路径的解决方案。我如何配置服务器(Apache),以治疗 http://my-server.com/holiday/ 作为根?

How would I go about this? I am looking for a solution that doesn't require me to change the path in my files. How do I configure the server (Apache) to treat http://my-server.com/holiday/ as a "root"?

澄清:
我还需要 http://my-server.com/ 来表现正常。也就是说,它应该仍然指向 http://my-server.com/index.html 即不会被重定向到 HTTP:/ /my-server.com/holiday /

Clarification: I still need http://my-server.com/ to behave "normally". That is, it should still point to http://my-server.com/index.html i.e. doesn't get redirected to http://my-server.com/holiday/.

推荐答案

我讨厌这样说,但没有上面提供了解决方案。通过@Zoltan和@stslavik的答案是接近,但不幸的是,在部署时没有工作;我希望他们中的一个工作,虽然。

I hate to say this but none of the above provides the solution. The answers by @Zoltan and @stslavik were close but, unfortunately, didn't work when deployed; I wished one of them worked, though.

这样一来,我使出使用名为的结合常数包括文件在PHP 的。更多细节:一个PHP项目 文件结构。需要注意的是它不必须是PHP;您可以使用提供类似功能的其他语言。 +1 @margusholland的答案使我这个解决方案进行试验。

As a result, I resorted to using a combination of named constants and include files in PHP. More details: File Structure for a PHP Project. Note that it doesn't have to be PHP; you can use other languages that provide similar features. +1 for @margusholland whose answer led me to experiment with this solution.

这篇关于在非根位置绝对路径部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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