0

I would like to understand how navigation works with sites with subdirectories.

For example, if I have this layout,

   \index.php
   \about_us\about_us.php

The navigation link for index.php to go back to homepage would be,

   <a href="./index.php">Home</a>

Whereas the one in about_us.php would be,

   <a href="../index.php">Home</a>

At the moment my solution is to simply put all the files in a subdirectory so that I can easily import the menu file into all the pages for easier management. For example,

   \index\index.php
   \about_us\about_us.php

I can then easily import a menu file,

   <?php include 'menu.php'; ?>

...into all my pages since I only need,

   <a href="../index.php">Home</a>

It doesn't seem like this is a good solution (everything in a subdirectory) for creating the navigation. Would like some advise on how this is done please. :) Thank you all.

DanS
  • 3
  • 1

1 Answers1

0

In general, it is considered best-practice to use relative URLs, so that your website will not be bound to the base URL of where it is currently deployed. For example, it will be able to work on localhost, as well as on your public domain, without modifications. -Daniel Vassallo.

However, if you are pretty sure you don't need relative URLs, you can use absolute URLs. In your case, to link to homepage from everywhere with the same anchor tag you would use:

<a href="/index.php">Home</a>
Community
  • 1
  • 1
Shef
  • 44,808
  • 15
  • 79
  • 90
  • 1
    Doh! That was nice and simple. Not sure why I never tried that. lol... Thanks muchly for that. :) – DanS Apr 02 '14 at 21:35