为什么我的超链接转到错误的目录? [英] Why do my hyperlinks go to the wrong directory?

查看:154
本文介绍了为什么我的超链接转到错误的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,功能就像我需要设置一个链接以指向:

  / site / sales / sold .php 

因此menu.php文件链接如下所示:

 < ul> 
< li>< a href =sales />销售< / a>< / li>
< li>< a href =sold.php>已售物品< / a>< / li>
< / ul>

有时会直接转到
<$ p $在下一刻,我们就可以看到,在一段时间内,我们可以看到,它重复菜单的目录,如:

  /site/sales/sales/sold.php 
$ b

$ b

  /site/sold.php 



如果您在页面上<$ c $

c> sales / 并链接到页面 sales ,链接将导致 sales / sales /

避免这种情况的默认方法是通过HTML < base>指定一个基本URL。 标签。这里没有涉及PHP,JS或CSS - 只是好的HTML 2.0。

 < base href =http: //www.example.com/site/\"> 

在你的页面头部使用这个,将给定的URL定义为页面上所有链接的基础,因此像 sales / 这样的链接实际上会导致 http://www.example.com/site/sales/ 当点击。



请参阅: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base


In my project functionality is like when i need to set a link to direct to:

/site/sales/sold.php

so the menu.php file link would look like this:

 <ul>
      <li><a href="sales/">Sales</a></li>   
      <li><a href="sold.php">Sold Items</a></li>
    </ul>

it would sometime direct to

/site/sales/sold.php 

and the next moment, it repeats the menu's directory like:

/site/sales/sales/sold.php

so i removed the sales directory, as its directing there by itself, worked for a little while and now it directs to

/site/sold.php

which does not exist so it ends up with a 404.

解决方案

If you are on a page sales/ and link to a page sales, the link will result in sales/sales/ – that is the defined behavior.

The default method to avoid that is to specify a base URL via the HTML <base> tag. There is no PHP, JS or CSS involved here – just good ol' HTML 2.0.

<base href="http://www.example.com/site/">

Using this in your pages head, will define the given URL as base for all links on the page, thus a link like sales/ will actually result in http://www.example.com/site/sales/ when clicked.

See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

这篇关于为什么我的超链接转到错误的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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