JeromeRo
JeromeRo

Reputation: 351

XAMPP is looking for images in htdocs instead of domain folder

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

Upvotes: 1

Views: 5433

Answers (2)

Vladimir Dimitrov
Vladimir Dimitrov

Reputation: 1088

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

Upvotes: 2

Annabel
Annabel

Reputation: 1414

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.

Upvotes: 1

Related Questions