404页未加载图像(文件源 /图层问题)

发布于 2025-01-25 01:44:15 字数 555 浏览 1 评论 0原文

我面临的可能是一个简单的问题,但尚未找到任何解决方案。

我最近刚刚在我的网站上构建了一个简单的404页( nofound.html ),该页面通过 .htaccess redirection( errordocument 404/ nofound.html )允许我捕获所有URL错误等。基本的。

问题是,由于可以在不同目录中称为,因此说例如 index /dir1 /dir1/dir2 等,页面不加载其样式和图像正确,因为源路径无法正确链接( image.png 正确链接从 index/nofound.html ,但应成为 ../ image.png 等,等等,等等。

我已经通过加载相同的样式表两次( styles.css ../ styles.css )来正确地加载样式。还没有找到任何解决方法(除了在分层目录中复制图像,这是笨重且多余的)。

有什么想法吗?提前致谢!

I'm facing what could be a simple problem, but haven't been able to find any solutions yet.

I just recently built a simple 404 page on my website (nofound.html) which through a .htaccess redirection (ErrorDocument 404 /nofound.html) allows me to catch all URL errors and such. Basic.

The problem is that, since the 404 response can be called within different directories, say for example index, or /dir1, or /dir1/dir2, etc, the page is not loading its styles and images right, since the source paths do not link correctly (image.png links correctly from index/nofound.html, but should become ../image.png and so on when going into different directory layers).

I've managed to make the styles load correctly by loading the same stylesheet twice (styles.css AND ../styles.css), but for the images, I have not found any workaround yet (other than duplicating the image within layered directories, which is cumbersome and redundant).

Any thoughts? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2025-02-01 01:44:15

尽管它不遵循最佳实践,但我的最终解决方案是简单地使用绝对超链接(例如 https://website/img.png 或类似的东西)而不是) 因此,网站锚点中的相对链接( ../../ img.png

因此,页面上的每个元素都从其绝对 - actual -directory 中加载,无论如何 nofound.html 结果与站点体系结构的其余部分之间的相对关系。

Although it does not follow best practices, my final solution was to simply use absolute hyperlinks (such as https://website/img.png or something like that) rather than relative links within the website's anchors (../../img.png)

As such, every element on the page is loaded from its absolute -actual- directory, regardless of the relative relationship between the nofound.html result and the rest of the site architecture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文