gwh Posted February 24, 2010 Share Posted February 24, 2010 Hi everyone, I have a page that's in a directory called 'business' that sits in the root directory of my site, ie. mysite.com/business/home.php This page (home.php) contains the following links in a common sidebar menu that exists on all pages of the site. The links point to a controller file called index.php which is located 2 directories within the 'business' directory: <div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=1"> Knitwear </a></div> <div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=2"> Shoes </a></div> <div><a href="catalogue/corporate/index.php?subcatID=1&itemTypeID=3"> T-shirts </a></div> So this controller file (index.php) is in a folder called corporate which is nested in a folder called catalogue which sits in the business directory (ie. the directory that holds home.php). If I click on say the "Knitwear" link, it will parse the code in index.php and then load an include file that will display the correct information for a slideshow (based on the variable values in the url string of the links). So the following code will load the slideshow template file: include 'catalogue.php'; exit(); The problem is that since the template file was loaded from the controller file (index.php), it's now located in a different directory and therefore if I click on any other link (which are available in the sidebar menu) the path no longer works. So if I click on say 'T-shirts' from this point, I get a page not found error. I tried changing the links to the following by putting in a forward slash: <div><a href="/catalogue/corporate/index.php?subcatID=1&itemTypeID=1"> Knitwear </a></div> but this didn't work. When I load home.php and then click on one of the links to go to the controller page, the address isn't complete so I get a page not found error. The following is what it loads: http://localhost:8888/catalogue/corporate/index.php?subcatID=1&itemTypeID=1 So it's missing the 'mysite' part and also the directory called 'business'. When testing locally It should be: http://localhost:8888//mysite/business/catalogue/corporate/index.php?subcatID=1&itemTypeID=1 I don't know how to solve this and wondered if anyone has any advice/workarounds? Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/ Share on other sites More sharing options...
schilly Posted February 24, 2010 Share Posted February 24, 2010 <a href="/mysite.com/business/catalogue/corporate/index.php?subcatID=1&itemTypeID=3"> T-shirts </a> relative links won't work in your case because you're changing your base dir when you click one of the links so you need to use absolute. Link to comment https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/#findComment-1017587 Share on other sites More sharing options...
gwh Posted February 24, 2010 Author Share Posted February 24, 2010 Thanks for the reply, Is there a php way to set the root directory? I just think the link is too long otherwise. Link to comment https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/#findComment-1017589 Share on other sites More sharing options...
teamatomic Posted February 24, 2010 Share Posted February 24, 2010 make a config.php file include it at the start of each and every page that uses links in the config.php file <?php $path='home/mysite/public_html/'; $path_business="$path/business/ $path_includes='home/mysite/public_html/includes'; $url='http://myDomain.com'; $url_business="$url/business"; $url_images="$url/images"; //and whatever else you end uo needing to make it easier. ?> Now when you build a link do it like so: echo "<a href=\"$url_business/catalogue/blah/blah\">link</a> HTH Teamtomic Link to comment https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/#findComment-1017594 Share on other sites More sharing options...
gwh Posted February 25, 2010 Author Share Posted February 25, 2010 Thanks so much - that's a perfect solution. Link to comment https://forums.phpfreaks.com/topic/193255-incorrect-file-paths/#findComment-1017902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.