8

I am currently working on codeigniter framework, 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)

Priyanka
  • 127
  • 1
  • 1
  • 11
  • 1
    file path incorrect or file permission problem – JYoThI Sep 09 '16 at 08:34
  • i have tried this in the separate folder, it working fine there. but when i am putting all these files into my view folder its giving the error in console – Priyanka Sep 09 '16 at 08:38
  • show me your file structure – JYoThI Sep 09 '16 at 08:41
  • Make sure you set your base_url in config.php –  Sep 09 '16 at 09:21
  • [This helped me a lot, you should have defined your css,images,js etc.(it is recommended) under any public folder. You can name it as assets/public... ](http://stackoverflow.com/questions/6630770/where-do-i-put-image-files-css-js-etc-in-codeigniter) – Priyanka Sep 10 '16 at 13:04

4 Answers4

5

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.

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

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.

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/

Tom
  • 2,543
  • 3
  • 21
  • 42
  • i have given the relative path but it is still stucked on the same error. – Priyanka Sep 09 '16 at 08:55
  • try the absolute path. Your relative path is probably wrong. If you use the absolute path and it works, you then know that is definitely the problem. For further help, post your file structure and the absolute path for your style.css that the browser constructs from the relative path. – Tom Sep 09 '16 at 08:56
  • I am working locally, on giving absolute path
    Not allowed to load local resource: file:///C:/xampp/htdocs/website/application/views/errorpage/web/images/background.pngconsole is giving this..
    – Priyanka Sep 09 '16 at 09:32
  • Yeah of course it will give that error if your try load an image from that directory, load images from a public directory that sits outside of your /application folder. Codeigniter protects files that sit inside /application, keeping them away from the public. – Tom Sep 09 '16 at 09:34
  • Yes, exactly. Take it out and put it in public or Codeigniter will not server it to the public. – Tom Sep 09 '16 at 09:38
  • Is there any way to fix this problem with .htaccess file? – Priyanka Sep 09 '16 at 09:39
  • No. Take the public assets and put them in a publicly accessible directory. – Tom Sep 09 '16 at 09:40
  • Thanks a lot Tom, it helped me. – Priyanka Sep 10 '16 at 12:41
0

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.

Hope it helps

Amaan Iqbal
  • 761
  • 2
  • 9
  • 25
0

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

Vikram Sapate
  • 1,087
  • 1
  • 11
  • 16
0

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