Search code examples
pathlivedevelopment-environmentmampabsolute

Paths on development and live servers


I'm looking for some advice, I currently use MAMP on locahost and have all of my websites in the htdocs folder. I use Codenighter mainly so when adding in paths for links, images etc I use <?php echo base_url(); ?> which is great for using the same code across live and dev.

I was wondering how I can link through to files from within a javascript file and preserve the paths when taking the site up to the live server?

I'm unable to put in absolute paths such as /controller/ as this doesn't work within the MAMP htdocs folder - I have to use /mysite/controller/ instead.

Is there a good way to preserve the paths when working across the two servers?


Solution

  • You should setup virtualhosts in Apache. By far the easiest way to do this is either get MAMP pro, or get VirtualHost X, the later is what I use. You can certainly setup virtual hosts in the Apache config but VirtualHost X adds the convenience factor.

    So for instance if my live site is example.com then I setup a virtual host locally called example.local.