html 设置基本路径会断开锚链接

ux6nzvsh  于 2023-03-16  发布在  其他
关注(0)|答案(2)|浏览(130)

我已经创建了一个WordPress主题和它的图像都打破了,所以我添加了一个基本路径标签的页面。

<base href="https://www.example.com/wp/wp-content/themes/my-theme/"/>

但是现在所有的锚/链接都不起作用了。

<a href="#an_id_on_the_page">click here</a>

上面的链接指向“https://www.example.com/wp/wp-content/themes/my-theme/index.php#an_id_on_the_page“,而不是同一个页面,但更向下。
WordPress建议在每个图片的路径中添加“”。但这意味着要中断工作流程,并在每次更改时编辑HTML代码。
有什么办法解决这个问题吗?

更新

如果我在锚前面加上一个“/”,它看起来就像是在工作。我会再测试一下以确认。

q3qa4bjr

q3qa4bjr1#

任何链接、命名锚点或空白href都不会指向原始子目录,除非明确指定:基本标记使所有链接都不同,包括指向基本标记url的相同页面锚链接,例如:

<a href='#top-of-page' title='Some title'>A link to the top of the page via a named anchor</a>
becomes
<a href='http://www.example.com/other-subdirectory/#top-of-page' title='Some title'>A link to an #named-anchor on the completely different base page</a>

<a href='?update=1' title='Some title'>A link to this page</a>
becomes
<a href='http://www.example.com/other-subdirectory/?update=1' title='Some title'>A link to the base tag's page instead</a>

通过一些工作,您可以通过显式指定这些链接链接到它们所在的页面,来修复您可以控制的链接上的这些问题,但是当您将依赖于标准行为的第三方库添加到混合中时,很容易导致大混乱。

一个月,

b4wnujal

b4wnujal2#

添加一个斜杠,“/”在手修复了许多问题。

相关问题