Forum Moderators: mack
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
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.
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>
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.
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.