Html 找不到 style.css 的 GET 404 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39407189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:47:34  来源:igfitidea点击:

GET 404 error for style.css not found

htmlcsscodeigniter

提问by jane

I am currently working on codeigniterframework, in the view i added my custom 404 error's page. But it is not loading the stylesheet from the folder errorpage/web/css/style.css. And i am getting an error in the browser's console GET : url/style.css 404(not found)(url is the address of my folder where my css file is)

我目前正在研究codeigniter框架,在视图中我添加了我的自定义 404 错误页面。但它没有从文件夹 errorpage/web/css/style.css 加载样式表。我在浏览器的控制台GET 中收到错误 :url/style.css 404(not found)(url 是我的 css 文件所在文件夹的地址)

采纳答案by Tom

404 is a 'not found' error. Meaning, the browser cannot find your style.css with the path it was given. If it is working on some templates and not others, it is because you may have a different file structure for some templates, a sub-folder for example.

404 是“未找到”错误。意思是,浏览器无法通过给定的路径找到您的 style.css。如果它正在处理某些模板而不是其他模板,那是因为您可能对某些模板具有不同的文件结构,例如子文件夹。

A quick fix would be to make your style.css load from an absolute path

一个快速的解决方法是让你的 style.css 从绝对路径加载

https://yourdomain.com/public/css/style.css

A better solution would be to traverse the directory to the css folder and then reference your style.css.

更好的解决方案是将目录遍历到 css 文件夹,然后引用您的 style.css。

Learn about relative paths and find a solution that works for all templates. The answer is likely to be something like:

了解相对路径并找到适用于所有模板的解决方案。答案很可能是这样的:

/public/css/style.css

However, it could be something like:

但是,它可能是这样的:

../public/css/style.css

Where goes back to one more previous directory. More about absolute vs. relative paths http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

哪里又回到以前的目录。更多关于绝对路径和相对路径http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

回答by Amaan Iqbal

You can try replacing the contents of original 404 Page Not Found error page with your custom error page. Make sure you doesn't change the name of that file or its location.

您可以尝试用您的自定义错误页面替换原始 404 Page Not Found 错误页面的内容。确保您没有更改该文件的名称或其位置。

Hope it helps

希望能帮助到你

回答by Vikram Sapate

Change <base href="/">to <base href="./">from index.html

更改<base href="/"><base href="./">from index.html

回答by Jan Rijavec

In my case problem was in incorrect file premissions (should be 644). In some cases is also smart to consider clearing cache in cloudflare.

在我的情况下,问题在于不正确的文件权限(应该是 644)。在某些情况下,考虑清除 cloudflare 中的缓存也是明智之举。