且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到404-指向CSS,图像的链接断开

更新时间:2023-02-26 13:09:58

这是因为您正在使用资源(CSS,JS和图像文件)的相对路径。您需要使用相对于根(以斜杠开头)或绝对URL。

This is because you are using relative paths to your resources (CSS, JS and image files). You need to use either root-relative (starting with a slash) or absolute URLs.

或者,使用 base head 部分中的>元素,它告诉浏览器相对URL相对于什么。例如:

Alternatively, use a base element in the head section that tells the browser what the relative URLs are relative to. For example:

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

(不过,请注意,使用库时有一些注意事项标签,如果您有页内锚点,例如 href =#top 或需要支持IE6?!)

(Note, however, that there are caveats when using the base tag if you have in-page anchors eg. href="#top" or need to support IE6?!)


但是,如果键入其他路径 http://example.com/another/test.html ,也会出现404页,但指向CSS和图像的链接断开了。

However, if you type in a different path http://example.com/another/test.html the 404 page comes up as well but the links to the css and images are broken.

例如,类似 css / normalize.css 将解析为 http://example.com/another/css/normalize.css ,当您期望它相对于文档根目录时。

For example, a URL like css/normalize.css in the page at this address will resolve to http://example.com/another/css/normalize.css, when you are expecting it to be relative to the document root.


此外,URL有时会解析为 http://example.com/example.com/kontakt 在其中具有实际域 example.com

这听起来像是您的某些链接中缺少该方案,例如:

This sounds like you are missing the scheme from some of your links, for example:

<a href="example.com/kontakt">Link Text</a>

应为:

<a href="http://example.com/kontakt">Link Text</a>

或者,亲戚协议:

<a href="//example.com/kontakt">Link Text</a>






另请参见我对这个问题的回答专业版网站管理员堆栈:
https://webmasters.stackexchange。 com / questions / 86450 / htaccess-rewrite-url-leads-to-missing-css