问题
Is this bad practise in any way?
The folder structure (every html page has filename index.html located in a subfolder):
root-folder (index.html)
subpage1 (index.html)
subpage2 (index.html)
subpage3 (index.html)
Index.html in root folder will have menulinks and like this:
<a href="/">index</a>
<a href="/subpage1">subpage1</a>
<a href="/subpage2">subpage2</a>
<a href="/subpage3">subpage3</a>
All other index.html files in the subfolders/subpages will have menulinks like this:
<a href="../">index</a>
<a href="../subpage1">subpage1</a>
<a href="../subpage2">subpage2</a>
<a href="../subpage3">subpage3</a>
Links to css, javascript, favoicon will also have this link structure.
I think the cleanest way would be to have links like this on every page. But it's complicated to work with if you want to try out the page in a subfolder...
<a href="/">index</a>
<a href="/subpage1">subpage1</a>
<a href="/subpage2">subpage2</a>
<a href="/subpage3">subpage3</a>
回答1:
The problem I have with an approach like this is that all your files are called 'index.html' and it's difficult to tell in your editor which is which. Also you have the problem of opening/closing each folder to navigate around and make edits, yuck.
What you can do to get the url's that you want is to use something like mod_rewrite to turn those nice-urls into the real filenames.
Add something like this for your .htaccess file:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
And in all your pages you'll be able to have links like the last example:
<a href="/">index</a>
<a href="/subpage1">subpage1</a>
<a href="/subpage2">subpage2</a>
<a href="/subpage3">subpage3</a>
回答2:
The cleanest way, like you said, is to use absolute paths, as in your second example. I would avoid using relative paths for the purpose that you have described.
来源:https://stackoverflow.com/questions/9221100/is-this-good-link-practice