Root Directory Confusion?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Root Directory Confusion?

Postby cmichaelryle » 25. January 2014 00:22

Installed XAMPP 1.8.3 and Wordpress 3.8.1.

Downloaded a Wordpress website so I could make modifications to it locally under XAMPP running on a Windows 7 laptop.

The downloaded site is up and running locally but the images will not load.

It appears to be because all the image HTML references are coded as <img src="/someimage.jpg"/>. If I change one of them to <img src="someimage.jpg"/> the image loads.

So HTML of the form <img src="/someimage.jpg"/> works on the host but not under XAMPP.

Anybody know why and/or how to fix it? Thanks for the help.
cmichaelryle
 
Posts: 3
Joined: 25. January 2014 00:10
Operating System: Windows 7

Re: Root Directory Confusion?

Postby Altrea » 25. January 2014 13:50

relative paths beginning with a slash take the domain root as base. Without slash the folder of the requested file is the base:

Example:

domain root
http://localhost/ => C:\xampp\htdocs\

index file in project folder
http://localhost/wordpress/index.php => C:\xampp\htdocs\wordpress\index.php

relative image url from file in project folder by domain root
<img src="/someimage.jpg"/> in index.php => C:\xampp\htdocs\someimage.jpg

relative image url from file in project folder by project folder
<img src="someimage.jpg"/> in index.php => C:\xampp\htdocs\wordpress\someimage.jpg
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Root Directory Confusion?

Postby cmichaelryle » 25. January 2014 14:23

The directory structure you show

C:\xampp\htdocs\wordpress\index.php

is I believe how it was when I first used XAMPP, under a prior release (I don't remember which), and I had no trouble getting the site to work under it.

However, after using the XAMPP and Wordpress installers provided by Bitnami to install the current release of XAMPP, 1.8.3, and WP the WP files now reside in:

C:\xampp\apps\wordpress\htdocs

For some reason WP running under XAMPP 1.8.3, unlike earlier releases of XAMPP, will not recognize a reference to C:\xampp\apps\wordpress\htdocs\images\someimage.jpg when coded as "src=/images/someimage.jpg" only when coded as "src=images/someimage.jpg". The same problem exists with relative pathnames used by the theme.

The reference "src=/images/someimage.jpg" works perfectly on the host where the site is live but not under XAMPP. If I have to change every one of those references (there are a great many) to get the site to work under XAMPP it isn't worth it.

I'm looking for a way to get the site to work under XAMPP as it does live and has in the past under prior releases of XAMPP without having to make changes the code.

Any ideas?
cmichaelryle
 
Posts: 3
Joined: 25. January 2014 00:10
Operating System: Windows 7

Re: Root Directory Confusion?

Postby Altrea » 25. January 2014 14:31

cmichaelryle wrote:If I have to change every one of those references (there are a great many) to get the site to work under XAMPP it isn't worth it.

You don't need to. Create a virtual host to simulate the url your live site is using.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Root Directory Confusion?

Postby cmichaelryle » 25. January 2014 18:27

How does one create a virtual host?
cmichaelryle
 
Posts: 3
Joined: 25. January 2014 00:10
Operating System: Windows 7

Re: Root Directory Confusion?

Postby Altrea » 25. January 2014 21:00

Bitnami already prepared everything to switch from Alias to virtualHost.
You can read everything about this here: http://wiki.bitnami.com/Components/Apache

In short: Change the Include line of your wordpress app in your \xampp\apache\conf\httpd.conf from httpd-prefix.conf to httpd-vhosts.conf
Then you should open the \xampp\apps\wordpress\conf\httpd-vhosts.conf file and change the lines Servername and ServerAlias to the domainname you want to use.
This domain name needs to be added to your Windows hosts file so that the domain gets resolved to your localhost ip 127.0.0.1

At the end restart your Apache.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 129 guests