HTML正斜杠链接不起作用 [英] HTML forward slash link doesn't work

查看:326
本文介绍了HTML正斜杠链接不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站地图是这样的:



文件夹'images'包含'image1.png',

文件夹'template'包含'header.php'和'footer.php',以及

'index.php'包括页眉和页脚。



现在进入header.php我有一个链接:

 <   img     src   =  images / image1.png >  



当我在localhost中运行index.php时,上面的链接在我按原样使用时工作正常,但在开头添加正斜杠,

 <   img     src   =  / images / image1.png >  



它已经死了!

当我搜索html / php链接时,我发现放一个正斜杠为链接创建了一种绝对路径,从根开始寻找文件。所以,我希望这可以工作,因为我在网站根目录中有图像文件夹。有人可以为我澄清这条路径差异吗?

解决方案

这不是斜线。 Slash确实有效;你没有。这是一个相对URL,相对于具有此 src 元素的HTML文件的位置。由于一些奇怪的原因,您没有在服务器上的适当位置,或者该目录不可访问。标准目录定界符应为'/';永远不要使用'\'。







参见解决方案2.〜/ *表示为站点配置的网站的根目录。同样,这不太便携,因为如果你只是在浏览器中打开文件而不使用任何HTTP服务器它将无法工作,因为在这种情况下没有这样的概念。即使在这种情况下,相对路径的工作方式也相同。



-SA


/ moves你了一个目录。所以,如果图像在root中,斜线会尝试从根开始提升你的水平。



如果它是.Net控件你可以用〜来根。 〜/图像/ image1.png。

My site map is like this:

Folder 'images' contains 'image1.png',
Folder 'template' contains 'header.php' and 'footer.php', and
'index.php' includes both header and footer.

Now in header.php I have a link:

<img src="images/image1.png">


When I run index.php in localhost, The above link works fine when I use it as is but with putting a forward slash at the beginning,

<img src="/images/image1.png">


it is dead!
When I googled about html/php linking I found out that putting a forward slash makes a kind of absolute path for the link, starting from the root and looking for the file. So, here I expect this to work because I have images folder in website root. Can someone please clarify this path differences for me?

解决方案

This is not a "slash". Slash does work; you don't. This is a relative URL, relative to the location of the HTML file with this src element. By some weird reason, you don't have it at appropriate location on the server, or the directory is not accessible. The standard directory delimiter should be '/'; never use '\'.

[EDIT]

See also Solution 2. "~/*" denotes the root of the Web site configured for the site. Again, this is less portable, because it won't work if you are just opening the file in browser, without using any HTTP server, because in this case there is no such notion. Relative paths would work the same way even in this case.

—SA


/ moves you up a directory. So, if images is in root a slash will try to put you up a level from the root.

If it's a .Net control you can use ~ to get to the root. ~/images/image1.png.


这篇关于HTML正斜杠链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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