Omzy Posted November 13, 2009 Share Posted November 13, 2009 I've got a localhost Apache server on my Windows machine I want to be able to create multiple sites under http://localhost, so for example: http://localhost/site1 http://localhost/site2 http://localhost/site3 The problem with this is that relative URLs don't always work, for example if I have a have a common header file (header.php) which contains a reference to a stylesheet (<link rel="stylesheet" type="text/css" href="styles.css" />) and I include() header.php on all pages, it won't work for pages that are in a subfolder of that site, for example: http://localhost/site1/subfolder1/index.php index.php includes header.php but the stylesheet reference points to the current folder, however styles.css is in the "root" of that site. If I change "styles.css" to "/styles.css" it looks in the root of "localhost" rather than the root of the site. So is there any way to specify in Apache/PHP what the base path of the site should be? I've tried "RewriteBase" in .htaccess but that doesn't quite work.. Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/ Share on other sites More sharing options...
mattal999 Posted November 13, 2009 Share Posted November 13, 2009 Not sure, but try this: <base href="http://localhost/site1/" /> Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/#findComment-957074 Share on other sites More sharing options...
micmania1 Posted November 13, 2009 Share Posted November 13, 2009 Lookup putenv() and getenv() functions. Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/#findComment-957083 Share on other sites More sharing options...
Omzy Posted November 13, 2009 Author Share Posted November 13, 2009 mattal - if I do that it won't work on the live server micmania - i'm not sure how to use those functions in my scenario Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/#findComment-957088 Share on other sites More sharing options...
Omzy Posted November 16, 2009 Author Share Posted November 16, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/#findComment-958696 Share on other sites More sharing options...
premiso Posted November 16, 2009 Share Posted November 16, 2009 You will have to setup a "config" to say for each site1 etc. Then before including header.php include that config.php which contains constants or variables, such as "SITE" IE: http://localhost/site1/config.php define("SITE", "site1"); http://localhost/site1/index.php <?php require('config.php'); require('../header.php'); ?> http://localhost/header.php <base href="http://localhost/<?php echo SITE; ?>/" /> <link href="style.css" type="text/css" /> Catch the drift? You will have to define it somehow, or else the script is just like anything else, it does not know how to decide what "you" want. Quote Link to comment https://forums.phpfreaks.com/topic/181428-set-a-base-path-for-each-site-in-localhost/#findComment-958699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.