OK, so, as I'm sure most of you are doing, I'm modifying my websites on my localhost. I have them under a folder to separate the website files from the XAMPP files. Now, I noticed that, since $_SERVER[HTTP_HOST] is localhost, all my links go to localhost/link_name, versus localhost/folder/link_name but ONLY when I'm using localhost, since I obviously don't want to switch anything when I go to my live server.

I've been trying to research how to accommodate so that I don't have to manually change the URLS with an if statement, but I can't seem to figure out how. I'm guessing the only way is to use .htaccess, but I can't find the code. I know I can do <a href="linkname">, but I hate that syntax as well, mainly because I have an include file that, even in the subdirectories, writes links to the main directory. I prefer to do <a href="/linkname">.

I have another folder for another website that I have, so I don't want to change the host name in http.conf. What are my options? I've tried looking this stuff up on Google, but the only answers I'm getting are for removing the www from the domain name.

[Edited to make paragraphs]

Last edited by KallistaAEnvarou on 07. December 2007 23:26, edited 2 times in total.

Have you tried/looked at creating virtualhost containers to separate your web content from the XAMPP localhost files?

xampp\apache\conf\extra\httpd.vhosts.conf

A search in the Xampp for Windows forum, category Apache Friends in English, using the keyword vhost or virtualhost will give some clues and example solutions - you can also add Izzy in the Search for Author field if you wish to narrow the search a little.

Try and split up your posts into separate paragraphs (lines) with a break in between for ease of reading.

===========================================1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlitePosted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open SourceFully working with NO donations required to get a user/password
===========================================

===========================================1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlitePosted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open SourceFully working with NO donations required to get a user/password
===========================================

OK, that didn't work. I did the VirtualHost thing just fine, and I got around Vista's inability to tell the truth about what it will and won't allow to happen so I could overwrite the hosts file, but I'm still not seeing any server link changes. I'll be honest that I haven't done the search yet since I've been kinda busy. I did read the links, and I already knew about all that stuff, though I didn't know the exact names. I want to use root-relative paths since, as I said before, I want to be able to use the links globally for my sub-folders.

## Virtual Hosts## If you want to maintain multiple domains/hostnames on your# machine you can setup VirtualHost containers for them. Most configurations# use only name-based virtual hosts so the server doesn't need to worry about# IP addresses. This is indicated by the asterisks in the directives below.## Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/># for further details before you try to setup virtual hosts.## You may use the command line option '-S' to verify your virtual host# configuration.

## Use name-based virtual hosting.###NameVirtualHost *:80

## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for all requests that do not# match a ServerName or ServerAlias in any <VirtualHost> block.###<VirtualHost *:80>## ServerAdmin webmaster@dummy-host.example.com## DocumentRoot /www/docs/dummy-host.example.com## ServerName dummy-host.example.com## ServerAlias www.dummy-host.example.com## ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log## CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common##</VirtualHost>

# Copyright (c) 1993-2006 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.## For example:## 102.54.94.97 rhino.acme.com # source server# 38.25.63.10 x.acme.com # x client host

This is incorrect and will fail.
ServerName localhost/phplearningneedsServerAlias localhost/phplearningneeds

Should be the same as you have indicated in your Windows hosts file.
ServerName phplearningneeds.comServerAlias www.phplearningneeds.com

Now it is available at these addresses (locally - not from the Internet unless you have registered the domain name etc.) because the server knows to look for phplearningneeds.com at the localhost location you specified in the DocumentRoot:
"C:/xampp/htdocs/phplearningneeds"

===========================================1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlitePosted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open SourceFully working with NO donations required to get a user/password
===========================================

No need for a ServerAlias in your case - read what a ServerAlias Directive is before you use it.

localhost/reportingscience - this is a URI not a ServerName and as I posted before, will fail - read what a ServerName is before using it.

Open a Command Console in xampp\apache\bin and at the prompt issue the command apache -S to verify the integrity of the httpd-vhost.conf file - which is clearly indicated in the readable sections of the httpd-vhost.conf file.

It seems to me you don't want to read the Apache Docs to find out the correct methods and directives to use, which will inevitably result in the simple mistakes you are making and consequently waste a lot of peoples time including your own.

===========================================1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlitePosted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open SourceFully working with NO donations required to get a user/password
===========================================

Nah, I've read them. I know that a ServerAlias is, as quoted, "Alternate names for a host used when matching requests to name-virtual hosts". I'm new to localhost servers, so I didn't know what that meant. I'm still not quite sure even though everything is working correctly now.

Anyway, I've fixed mine up in a compromised way. I'm going to use local_websitename for the Server Names, since apparently the Aliases don't do anything...or do they?. Anyway, thanks a bunch. You're awesome.

Even if you don't use it for your current path issues, the reading will definitely broaden your understanding of what can be achieved using the .htaccess file to change the default behavior of the server on an individual directory basis.

BTW ServerAlias are alternative ServerName(s) that all point to the same vhost DocumentRoot if used in a URI.

For example:
ServerName server.tld
ServerAlias www.server.tld server server.server server_server.tld
(etc. as many as you need all on one line each alias separated by a single space)
DocumentRoot "C:/xampp/htdocs"

Another virtual host container is required if the DocumentRoot is different, as in the case of a subdomain.

===========================================1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlitePosted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open SourceFully working with NO donations required to get a user/password
===========================================

OK, so you mean the ServerAlias would be like if I were to type php.com I could get localhost_phplearningneeds.com? That'd make sense.

As far as my .htaccess is concerned, I have my .htaccess set up to redirect every page my site encounters to go to the /index.php page. I do that because validator.w3.org can tell if a site has a fake 404 page, which I don't want. Then my index.php page processes everything, and I have headers for images and css files, but the only thing is that I can't figure out how to do headers for JavaScript files. Eh, I'll figure it out eventually.

PS I said you're awesome because you helped me solve my issue. Plus, everybody, even if in a sick way, has a little dose of awesomeness.