问题
I want to make multiple pages on my website, but to keep everything clean I want to make different directoriess with the different pages. However, I use php to make a different file with my header that is included in all my pages, so I only have to change the code of my header once and it will be the same on all pages.
The problem is that the links I use in my menu items (like home, contact, about, etc.) will not work anymore when you're on a page inside a directory (I'll make an example below).
So my question: Is there a home folder on a website (like ~/ on unix) or is there another way to make it work?
Example of my directory structure:
htdocs
index.php
header.php
menus
contact.php
about.php
(a link to index.php won't work anymore if you're on the contact.php page)
回答1:
Sounds like you're using relative paths in your menu links. Use an absolute path instead by starting with a "/":
<a href="/index.php">Home</a>
<a href="/menus/about.php">About</a>
or a complete URL:
<a href="http://example.com/index.php">Home</a>
<a href="http://example.com/menus/about.php">About</a>
回答2:
The home directory of a website can be accessed with a simple '/' at the start of the link you want to add. From there you can enter subfolders by appending the folder name.
Example: 'example.com/subfolder/subsubfolder/page.html'
来源:https://stackoverflow.com/questions/44029394/links-not-working-from-subdirectories