404页未加载图像(文件源 /图层问题)
我面临的可能是一个简单的问题,但尚未找到任何解决方案。
我最近刚刚在我的网站上构建了一个简单的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管它不遵循最佳实践,但我的最终解决方案是简单地使用绝对超链接(例如 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.