adipalmer123 Posted March 13, 2012 Share Posted March 13, 2012 Hi all My site is build using php includes. the index.php file contains code like <?php if(@$_GET['page'] == "web-design"){ include("includes/web-design.php"); } else if(@$_GET['page'] == "hosting"){ include("includes/hosting.php"); } else { include("includes/home.php"); } ?> I have created a sub domain blog.maplewebdesign.co.uk and a sub dircetory named blog. The link to this part of my site doesn't use includes, I want it to link directly to that sub directories index.php page. This works fine, but then when I click on a different link anywhere on the site my url is as follows www.maplewebdesign.co.uk/blog/index.php?page=home For some reason it is keeping the blog/ in the URL If you want to see go to http://www.maplewebdesign.co.uk/blog/ then click on a differnt link and check out the URL What am I doing wrong? Thanks Adi Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/ Share on other sites More sharing options...
Mahngiel Posted March 13, 2012 Share Posted March 13, 2012 visiting your site under http://www.maplewebdesign.co.uk/blog/, the site URI will retain /blog/, but when you visit under http://www.maplewebdesign.co.uk/, your URI is preserved. if you run apache, you can get rid of that uri segment with .htaccess Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326805 Share on other sites More sharing options...
adipalmer123 Posted March 13, 2012 Author Share Posted March 13, 2012 Right got you. I'm very new to apache and .htaccess etc. Could you tell me what I'd need to write for this please? Thanks Adi Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326806 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 $_SERVER['DOCUMENT_ROOT'] contains the full path to the root of your webserver. Use that in all your include() and require() statements so that regardless of how "Deep" you are in the folder structure, your includes will always go to the right file. You don't need to mess with htaccess for this. Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326817 Share on other sites More sharing options...
adipalmer123 Posted March 13, 2012 Author Share Posted March 13, 2012 I can see what you mean, I've had a little play about but still to no avail. In my index.php file i've done the following <?php if(@$_GET['page'] == "web-design"){ include($_SERVER['DOCUMENT_ROOT'].'/includes/web-design.php'); } else if(@$_GET['page'] == "hosting"){ include($_SERVER['DOCUMENT_ROOT'].'/includes/hosting.php'); } else { include($_SERVER['DOCUMENT_ROOT'].'/includes/home.php'); } ?> Is this right? Also Just to give you a little bit more info, my left nav comprises of the following: <li class="home"><a href="index.php?page=home"><div class="text-hide">home</div></a></li> <li class="web-design"><a href="index.php?page=web-design"><div class="text-hide">web design</div></a></li> <li class="hosting"><a href="index.php?page=hosting"><div class="text-hide">hosting</div></a></li> I've added the $_SERVER['DOCUMENT_ROOT'] into my index.php file but I'm still getting the same problem. the "blog/" part of the url is still there Am I missing something Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326896 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 1) I don't know if your includes are right because only you can tell us that. Print out the complete string you're including and see if it's pointing to the right file. If so, it's right. 2) Your links are all relative as well, you need to use your full domain or start your links with a / Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326901 Share on other sites More sharing options...
adipalmer123 Posted March 13, 2012 Author Share Posted March 13, 2012 Perfect! It was the "/" infront of the links that was the problem. Thanks very much for the help. Quote Link to comment https://forums.phpfreaks.com/topic/258825-url-incorrect-on-php-includes/#findComment-1326905 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.