XAMPP is looking for images in htdocs instead of domain folder

时间秒杀一切 提交于 2019-12-08 06:46:02

问题


I am running XAMPP 1.8.2 Inside of htdocs folder I have a several sites. Now I downloaded a working website from my hosting/server and found out that the identical copy of that website run on Xampp [http://localhost/mysite] can not find the images. It is looking for images on [http://localhost/img/myimage01.jpg] instead of [http://localhost/mysite/img/myimage01.jpg]

I read some solutions but they all come to pointing the whole thing to [http://localhost/mydomain] I would prefer if I can tell XAMPP to look for files for every domain from it's own root directory.

How can I do this? Thanks


回答1:


The easiest way is to create separate virtual host for each site folder in /htdocs So you will access the http://mysite.local instead http:// localhost/mysite

There are two things to do: 1. edit C:\xampp\apache\conf\extra\httpd-vhosts.conf (by default) adding something like

 <VirtualHost *:80>
 ServerName      mysite.local
 DocumentRoot    C:/XAMPP/htdocs/mysite
 </VirtualHost>

2. edit c:\windows\system32\drivers\etc\hosts adding

127.0.0.1       mysite.local

restart xampp and try http://mysite.local




回答2:


You generally can't move a whole website from http://<somedomain> to http://<somedomain>/<somefolder>. Things are bound to go wrong with links between pages in the site and links within pages to images.

Let's say you are displaying images within HTML web pages using image tags like this:

<img src="img/myimage01.jpg"></img>

This will probably work as the browser will look for the img folder in the same folder as the web-page.

On the other hand if your image tag looks like this (note the extra /) you will have the problem you describe:

<img src="/img/myimage01.jpg"></img>

The extra / means the browser will look for the img folder at the root of the domain.



来源:https://stackoverflow.com/questions/19338068/xampp-is-looking-for-images-in-htdocs-instead-of-domain-folder

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