如何使链接工作,不管目录结构中的位置? [英] How to make links work, regardless of location in directory structure?

查看:84
本文介绍了如何使链接工作,不管目录结构中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在包含的图片中,您可以看到我目前正在处理的网站的副本。该网站将为每个公司的机器具有单独的页面。显然,导航栏和菜单栏将在整个网站上是相同的,所以我想我会使用一行PHP脚本只是每次加载菜单。

So in the included image, you can see a copy of the website I'm currently working on. The site is going to have separate pages for each of the company's machines. Obviously the navigation bar and menu bar are going to be the same throughout the whole website so I thought I'd make use of a single line of PHP script to just load the menu in each time.

http://i.imgur.com/spVS3a4.png
(附加图像,因为我还没有+10 rep)

http://i.imgur.com/spVS3a4.png (Attached image as I do not have +10 rep yet)

虽然,从我的理解,文件夹内的页面(不在根内)不能链接到网站的其余部分,而不使用 href 中的 ../

Though, from what I understand, the pages within folders (Not within root) wont be able to link to the rest of the site without the use of ../ within the href.

因此,如果我加载包含navbar等的网站的菜单部分,它不会在所有的网页上工作,因为他们都将在不同的文件夹,意味着每个文件夹将需要它自己版本的导航栏PHP导入。

So if I load the menu part of the site containing the navbar, etc, it won't work on all the pages because they'll all be within different folders, meaning every folder will need it's own version of the navbar PHP import.

我这是错误的方式吗?我只是想尽量减少我在每个页面上使用的代码量。不仅如此,但一旦我完成网站,如果我要更改菜单栏,我不想更新30-40 +页。我认为PHP导入会救我那种麻烦?有没有更好的方法这样做,这是不是很复杂?

Am I going about this the wrong way? I'm just trying to minimize the amount of code I'm using on each page. Not only that, but once I finish the site if I have to make a change to the menu-bar, I don't want to have to update 30-40+ pages. I figured the PHP import would save me that sort of trouble? Is there a better way of doing this that isn't terribly complicated?

还应该注意,我这样做在HTML5与Twitter-Bootstrap作为我的主CSS。

It should also be noted that I'm doing this in HTML5 with Twitter-Bootstrap as my main CSS.

我也会做一个类似的PHP调用,也会导入一个页脚。

I would also be making a similar PHP call that would import a footer as well. If I missed anything that could be of help, please do ask.

TL; DR - 如何让链接工作整个网站,无论他们在文件夹层次结构中的位置。思考使用一个小的PHP脚本,将包含菜单栏等,并将加载到每一个页面。

TL;DR - How do I make links work throughout the entirety of the site, regardless of where they are in the folder hierarchy. Thought about using a tiny PHP script that would contain the menubar, etc and would be loaded on every single page. Though I'm not sure if that will work due to folders?

推荐答案

尝试从 / 。这意味着网站从网站根启动。
例如:

Try to start your links from /. This means that url is started from site root. For example:

<a href="/products/kettles/kettles_patch.html">Patch Kettles</a>

这篇关于如何使链接工作,不管目录结构中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆