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
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
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.
Related
I have two domains pointed to the same server.
olddomain.com is configured such that DocumentRoot is /var/www/html (Apache server) and finds all HTML and PHP files here. What is the simplest way to have newdomain.com find it's files (different from olddomain.com's) from a different folder (say /var/www/html2), such that when I type:
newdomain.com, it'll show a default index page
newdomain.com/foobar.htm it'll show newdomain.com/foobar.htm (including seeing this in the URL bar)
?
Create virtual hosts for each domain, very easy to do, Google it.
I have been running a co-located Linux box with several httpd vhosts. A few years ago I recovered an archived web site and added it to an existing domain as a directory under htdocs as a sub-site. It is an older site that uses frames but works correctly underneath the main domain.
The old website has nostalgic value to certain hobbyists and a couple of weeks ago I decided to acquire another domain so that this sub-site could be accessed directly. However, the frames do not get set up correctly and the pages do not display like they should - stuff is obviously missing.
I have tried several things but no avail. Currently both domains point to the same location.
Here is my Apache config for the main site (http://www.vintagewargamingfigures.info/):
<VirtualHost 64.182.125.197:80>
ServerName www.vintagewargamingfigures.info
ServerAlias vintagewargamingfigures.info
DocumentRoot /local/web_sites/vintage/htdocs
</VirtualHost>
Here is the config for the sub-site when it fails (http://www.vintage20mil.com/):
<VirtualHost 64.182.125.197:80>
ServerName www.vintage20mil.com
ServerAlias vintage20mil.com
DocumentRoot /local/web_sites/vintage/htdocs/rblack
</VirtualHost>
The document root shows the site as being in a directory (rblack) under the main site.
Google Chrome has fooled me a couple of times and it looks like it was working but sometime later it will not work. So, I also use MS Edge to test it.
I have tried several things, including running some symbolic links directly to the rblack directory but haven't found the cure yet.
What am I missing? I suspect it is something simple but it is eluding me.
Any help appreciated.
.......CG
I have read other answers here on this site, but they only answer part of my question. I have XAMPP for Windows 7.2.0-0 on my computer. I have partitioned my hard drive to add an E: drive. My htdocs folder is in C: drive and I have a FQDN pointing to my ip address; say (example.com).
Next I created a directory in E: named 'me'; which contains all the files for a functioning website.
Now, after following all the directions from cmcculloh, I can just type me.example.com in my browser and up pops the website, but this URL does not work from any other computer. Could someone help me to understand how I need to configure The 'httpd-vhosts.conf' & 'hosts' files; along with, what the proper URL address should be to view the website located in 'E:me' from a remote computer.
Here is what I have done in 'httpd-vhosts.conf':
<VirtualHost *:80>
DocumentRoot "E:/me"
ServerName me.example.com
ServerAlias me.localhost
<directory E:/me>
Require all granted
</directory>
ErrorLog "E:/me/logs/error.log"
TransferLog "E:/me/logs/access.log"
</VirtualHost>
I have tried many different variations with the server name and alias but none work any better.
Here is what I have done in 'hosts':
127.0.0.1 me.example.com
Like I said this works in the browser of the computer that the server is on, but trying to view this site from another computer I get "This site can't be reached" "me.example.com's server IP address could not be found".
Am I 'barking up the wrong tree' by approaching it like this, or should I be researching how to add the contents of a separate drive to the htdocs folder. I am at a loss as to how this can be achieved. My hard drive is near full and I need to add more storage space, but have to figure this out before I purchase more hardware.
Solution by OP.
To accomplish my goal of accessing the pages from a remote computer I had to use the command mklink /J. The example below created a directory named 'my' in my 'htdocs' linking to everything on my 'E:' drive.
mklink /J C:\xampp\htdocs\my E:
The only thing I don't like about it is that in order to view the webpage in E:/me, I have to type the URL example.com/my/me instead of example.com/me. I know it's not a big deal having to type the extra directory 'my' in the URL, but I just don't like the look of it. Also this negates the need to add 'VirtualHosts' and 'mapping'; although, I may have to do that anyway with '.htaccess' to keep users from accessing directories other than theirs.
I installed WAMP Server on my laptop, which is running Windows 8 Pro.
I created a number of folders in the www folder in the wamp folder. My problem is that whenever I try accessing the folders from the localhost page in my web browser, I am taken to the internet page of the folder i.e. I have two folders named family & prestashop. Whenever I click on them, a tab opens in my browser directing me to http://family/ instead of http://localhost/family/
What could be the problem?
Without seeing your httpd.conf (or httpd-vhosts.conf) it is hard to say where your problem is (or why it is a problem). Usually, to set up multiple sites, you will add virtual hosts to your httpd.conf or httpd-vhosts.conf which will tell WAMP what to do when people try to access that folder. The difference between a web address that looks like http://localhost/family and http://family is probably that you have set up a virtual host which allows you to get at that directory without running through 'localhost'.
Do you have something like this in your http-vhosts.conf in C:\wamp\bin\apache\Apache<version>\conf\extras\ ?
<VirtualHost *:80>
DocumentRoot "C:\wamp/www/family/"
ServerName "family"
</VirtualHost>
Using apache 2, I have a simple virtual host container:
<VirtualHost 127.0.0.1>
ServerName developmentServer
DocumentRoot /var/www
</VirtualHost>
The site is accessible, but I'm having trouble using root relative links within the site. I have an 'images' folder that is located at the root level. When I am within a folder or subfolder, I want to specify an image path that is root relative. (And actually all paths will be root relative regardless of the page depth.) This currently is not working:
<img src="/images/file.jpg">
But this will:
<img src="../images/file.jpg">
I understand the difference, but I do not know what needs to be changed in Apache to allow me start all links with a "/" so they are root-relative. I'm thinking there is a configuration setting, and I shouldn't have to rely on mod_rewrite. Any suggestions?
Is the image located at /var/www/images/file.jpg and are you accessing the page containing this image over HTTP (http://developmentServer/...)? Then it must work.