Localhost Development URLs

Soldato
Joined
10 Dec 2003
Posts
6,348
Is there any way I can develop a site localy, without worrying about changing the URLs when it comes to uploading to a web server?

Sometimes I run into problems where some scripts require absolute paths to other scripts, and then I have to go through and change them all once I'm ready to upload. It's slow and tedious.

Surely there must be some kind of htaccess-like control for telling the browser that should be shown as , ignoring 'localhost'.

Or some kind of a switch to change the name of 'localhost' to the actual project domain I wish to work on, at any one time.

I'm using XAMPP and I've tried searching their Apache Friends forum for some answers, but I've had no luck.
 
add NameVirtualHost and VirtualHost directives in your httpd.conf, then edit your hosts file and add the name of your virtual host to point to 127.0.0.1, then restart apache.

here's a copy of my virtual hosts definition:

Code:
NameVirtualHost 127.0.0.1
<VirtualHost *:80>
    DocumentRoot "/Users/Jasper/Sites"
		ServerName localhost
		ServerAlias localhost
</VirtualHost>
<VirtualHost django>
    DocumentRoot "/Users/Jasper/Sites/django/first"
		ServerName django
		ServerAlias django
		<Location />
		    SetHandler python-program
		    PythonHandler django.core.handlers.modpython
		    SetEnv DJANGO_SETTINGS_MODULE first.settings
				PythonPath "['/Users/Jasper/Sites/django'] + sys.path"
		    PythonDebug On
		</Location>
		<Location "/media">
		    SetHandler None
		</Location>
		<LocationMatch "\.(jpg|gif|png)$">
		    SetHandler None
		</LocationMatch>
</VirtualHost>
<VirtualHost fw>
    DocumentRoot "/Users/Jasper/Sites/fw"
    ServerName fw
    ServerAlias fw
</VirtualHost>
<VirtualHost akof>
    DocumentRoot "/Users/Jasper/Sites/akof"
    ServerName akof
    ServerAlias akof
</VirtualHost>
<VirtualHost blog>
    DocumentRoot "/Users/Jasper/Sites/blog"
    ServerName blog
    ServerAlias blog
</VirtualHost>
 
You could also edit the windows 'hosts' file (I think it's in c:\windows). Add something like:
domain.com 127.0.0.1
Then set the the apache server name to domain.com; probably best using VirtualHosts here (as above) so you don't have to keep editing the apache config each time you work on a different site.

This way, whenever you enter domain.com into the browser, you'll be connecting to the localhost webserver (and obviously, if/when you want to connect to the *real* domain.com, you'll have to delete the line in hosts).

edit: Should have really read the above post properly, I missed the first line :(
 
Last edited:
Back
Top Bottom