Forum Moderators: mack

Message Too Old, No Replies

Develop subdomains locally before upload

Can't figure out the best way to link to them

         

proper_bo

9:26 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



My problem is this:

I want to use the same menu.php on every page with a php include tag and still have it link to the correct pages. I could do this by hard coding all the links into the menu but then this causes havoc while I develop the site locally on my computer at home.

I aim to link to subdomains in the menu but have those links still work when developing locally.
Can I rewrite (for example) forum.site.com to localhost/forum/ or 127.0.0.1/forum/ or can I get subdomains to work on localhost?

I am currently setting $root in all the pages that include files from /includes/ folder such as header, footer and menu and then in these files all links are referenced as ($root . 'folder/file.php') to make all the links work however deep the folder structure goes. My main problem is the subdomains really. How to link to them and develop them.

I have searched for an answer both here and on search engines but to no avail. Sorry if this has been discussed before.

Proper_bo

timchuma

9:32 pm on Feb 15, 2005 (gmt 0)

10+ Year Member Top Contributors Of The Month



I found the best way to work with subdomains locally was to treat them as their own site and just link to the other domains with absolute paths.

Ocassionaly you will click on a link and not be able to load a page (if you are not on the internet) but it helps keep your site organised.

Thanks.

caspita

9:32 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Here is what I use:


$root = 'http://' . $_SERVER['SERVER_NAME'] . '/';
if ($_SERVER['SERVER_NAME'] == 'localhost') $root .= 'localfolder/';

Then all mi links are 'absolute links' and my prefix is $root like:


<a href=<? echo $root;?>sitemap.html>SiteMap</a>

I hope this helps ;-)

Carlos.

proper_bo

9:38 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Carlos,

Do you change the localfolder/ for every page?

A way I have considered doing it is this:

if ($root == './')
{
//define('OPINION_ROOT', $root . 'opinion/');
$opinion_root = ($root . 'opinion/');
$football_root = ($root . 'football/');
$forum_root = ($root . 'forum/');
$shop_root = ($root . 'shop/');
$mobile_root = ($root . 'mobile/');
}else{
$opinion_root = 'http://opinion.site.co.uk/';
$football_root = 'http://football.site.co.uk/';
$forum_root = 'http://forum.site.co.uk/';
$shop_root = 'http://shop.site.co.uk/';
$mobile_root = 'http://mobile.site.co.uk/';
}

put this in a common.php page linked to on every page and then have a different file for local and online.

As long as images are also linked to with the $root . 'images/img.jpg') they should be alright too yeah?

Otherwise maybe a new 127.0.0.1/2/3/4 for each subdomain is the way to go. A pain though.

proper_bo

9:45 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Just found this:
Could be the answer.

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs"
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName subdomain.localhost
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs/folder_name"
</VirtualHost>

caspita

10:09 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Hi proper_bo,

Sorry I didn't get well your question at the begining, I was assuming your scenario was similar to mine. In my case all my pages point to the same subdomain.. then I have a subdomain for each theme in my hosting and in my local PC I have each subdomain in a folder.. but I do not link that much between subdomains.

Your last suggestion may work also for Apache webserver.. is not my case because I use IIS in my local PC .. I'm not appache expert either, so I can not confirm.

Carlos.

proper_bo

10:57 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Ok I finally worked out how to do it! and it only seems fair that I should leave it here for anyone else to find in the future.

To add subdomain.localhost to your apache httpd.conf you need to take the following steps:

1) set httpd.conf with:

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot C:\server\Apache\htdocs\site
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>

<VirtualHost 127.0.0.2>
ServerName subdomain.localhost
DocumentRoot C:\server\Apache\htdocs\site\subdomain
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>

save and exit

2) edit C:\windows\system32\drivers\etc\hosts (using a text editor) and add the line
127.0.0.2 subdomain subdomain.localhost
after the 127.0.0.1 line. Save and exit.

restart apache. Go to subdomain.localhost and find the correct content there. Good luck. I can't believe there isn't a single good tutorial about this anywhere findable on the internet.