I'm new to making websites using PHP includes (normally everything would be Dreamweaver templates and library items). I'm still using DW templates, but all of the navigation, header and footer are all PHP includes. When I make a new page, say one directory inside of the root, DW automatically updates the references to the include files, which is nice. What DW doesn't do though is update the relative references inside those include files. So for pages in the root directory there is no problem, but for pages at any sub-level, no images display, and none of the nav links work.

So the problem I'm running into is that I can't navigate the site on my localhost, because the navigation links are all staying relative to the location of the navigation include file. So, you might say, why don't you just convert them all to absolute links? Because if I do that, I still can't navigate on Localhost because absolute links will shoot me to the online domain.

How do I get around this? Is there some way in PHP to automatically update img src references and link references based on where the page resides in relation to the site root?

Let me know if I need to explain this better. BTW, the reason I'm still doing DW templates with this is because I think it's better for SEO purposes to have actual pages instead of loading content via includes - "?page_1", etc. This is a medium-sized site I'm working on with a lot of pages and directories, so it's not like I can just put all my pages at the root level and not have this problem.

Thanks in advance.

Randy

You got any code examples you can provide?

One way out of this would be to define a variable when you do your initialization (e.g. in your initial index.php module or a config module) for the address of your root directory. In your navigation module, all link addresses would be relative to that root address (e.g. $path_root."/abc/aaa.php"). That way, no matter where you are (or on what version of the site), the addresses are all in relation to a standard starting point for that specific version of the site.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.