我应该在网站中使用相对路径吗?或者没关系? [英] Should I use relative path for pages within the site? or it doesn't matter?

查看:125
本文介绍了我应该在网站中使用相对路径吗?或者没关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道什么是定义链接到域名内页面的URL的最佳方式。例如,对于域www.example.com ..我可以有像

< a href =http:// www。 domain.com/test.html\"> test</a>





< a href =test.html> test< / a>

我遇到的问题是,虽然使用模板..如果我使用相对链接的HTML模板,然后我不能使用目录www.example.com/directory2相同的模板,因为常见的链接将无法正常工作page ..既不是css也不是javascripts文件。



我必须复制模板或完全设置路径。我选择了绝对路径。所以模板路径以 http://www.mydomain.com/ 开头..这是否会导致任何性能问题像多个http请求,域名解析或其他?你对此有何建议/评论?



谢谢。

解决方案

使用绝对路径不会添加任何额外的开销,本地链接的公认惯例是使用相对链接。相对链接可以通过诸如wget或Down-The-All(网站下载工具)等工具与绝对链接区别开来。然而,如果您的模板解决方案最适合绝对的联系,那么坚持下去并不是闻所未闻的。暂时,如果您的网站内容被链接回您的原始页面,绝对链接可以发挥您的优势(来源: http://www.navegabem.com/linking-strategy.html )。


I was just wondering what is the best way to define urls linking to pages within a domain name. For example, for domain www.example.com .. I can have links like

<a href="http://www.domain.com/test.html">test</a>

or

<a href="test.html">test</a>

One of the issues, which I came across was that while using templates .. if I use html template with relative links then I can't use the same template for directory www.example.com/directory2 as the common links won't work for that page .. neither the css nor javascripts files.

I either had to duplicate the template or set paths absolutely. I chose absolute paths. so template paths start with http://www.mydomain.com/ .. Does this cause any performance issue like multiple http requests, domain resolving, or any other? what is your suggesstion/comment on this?

Thanks.

解决方案

While using the absolute path does not add any additional overhead, the accepted practice for local links is to use relative links. Relative links can be treated differently from absolute links by such tools as wget or Down-Them-All (website downloading tools).

However, if your templating solution works best with absolute links, then it is not unheard of to stick with them. Tentatively, absolute links can work to your advantage if your site's content is scraped by linking back to your original page (Source: http://www.navegabem.com/linking-strategy.html).

这篇关于我应该在网站中使用相对路径吗?或者没关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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