XAMPP中的根路径 [英] Root path in XAMPP

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

问题描述

 < p> img src =/ images / test.jpg/> 

从(根路径 - 在我的LAMP生产中)获取图像

  htdocs / images / test.jpg 

是否从htdocs / index.php或htdocs / foo / bar / index.php中调用

我在开发中使用XAMPP,并且在htdocs中有项目文件夹,所以上面描述的方法虽然会在我需要改变它时生效:

 < img src =/ projectName / images / test.jpg/> 

在本地工作时。



这个简单的我定义了一个常量BASE,在开发中我使用:

$ p $ define('BASE','/ projectname /)

然后当它生效时,我将更改为:

  define('BASE','/')

这显然非常令人讨厌,最终导致了几个问题。请有人可以对这种情况作一些说明,我特别想要做的是在我的图像/脚本源中使用根路径,但是:

 < img src =/ images / test.jpg/> 

从htdocs / projectName / foo / test.php中调用时

查找图像:

  htdocs / projectName / images / 

这可能吗?

解决方案

处理这个问题的另一种方法是使用虚拟主机。

虚拟主机就像专门用于子文件夹的localhost的第二个版本。例如,你可以设置Apache,以便当你访问 http:// example (no .com 或其他任何东西),它会显示来自 http:// localhost / example / 的内容。所有CSS,JavaScript和链接的行为就好像它们是从网站的根文件夹操作的,因为前面的示例文件夹已被删除掉。



我无法找到演练我曾经使用过XAMPP,但这里有一个涵盖所有要点的类似内容。它是为Windows编写的,但我想像有类似的机制可以用于LAMP:



总之,下面是文章告诉你要做的事情: p>


  • 在Apache中启用虚拟主机
  • 设置它以便当您访问例如,您被发送到 127.0.0.1

  • 配置Apache,以便当有人访问 127.0.0.1 (但是网站的名字是 example ),那么它显示来自例子的内容文件夹。


这就是您的制作网站(包含多个网站的单个服务器)不同的根为每个网站。


I've had this problem for a while, and have unsuccessfully searched far and wide for an answer.

 <img src="/images/test.jpg" /> 

Gets an image from (root path - in my case in production in LAMP)

 htdocs/images/test.jpg 

Whether it's called from htdocs/index.php or htdocs/foo/bar/index.php

I use XAMPP in development, and inside htdocs have project folders, so the method described above although will work when live requires me to alter it to:

<img src="/projectName/images/test.jpg" /> 

when working locally.

To make this simpler i define a constant BASE, which in development I use:

define('BASE','/projectname/) 

And then when it's live I change to:

define('BASE','/')

<img src="<?php echo BASE;?>images/test.jpg" />

This is obviously really annoying and ends up causing several issues. Please can someone shed some light on this situation, what I'm specifically looking to do is use root path in my image/script sources but for:

<img src="/images/test.jpg" />

when called from htdocs/projectName/foo/test.php

to look for the image in:

htdocs/projectName/images/

Is this possible?

解决方案

An alternate way to handle this is with the use of Virtual Hosts.

A virtual host acts like a second version of localhost that works specifically for a subfolder. For example, you could set up Apache so that when you visit http://example (no .com or anything), it shows you the content from http://localhost/example/. All CSS and JavaScript and links would act as if they were operating from the root folder of a website, since the leading example folder has been trimmed out of the URL.

I can't find a walkthrough that I used to use for XAMPP, but here a similar one that covers all of the main points. It was written for Windows, but I imagine that there are similar mechanisms that you can use for LAMP:

To summarize, here's what the article tells you to do:

  • Enable Virtual Hosts within Apache
  • Set it up so that when you visit example, you are sent to 127.0.0.1
  • Configure Apache so that when someone visits 127.0.0.1 (but the name of the website is example), then it shows content from the example folder.

This is how your production site (which is a single server with multiple websites) has a different "root" for each website.

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

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