0

How would I render favicons in Lithium?

Right now I have this in my layouts:

<?php echo $this->html->link('Icon', null, array('type' => 'icon')); ?>

However, the favicon doesn't show up. Attempting to view the favicon resource via Chrome Inspector shows me a broken image.

I tried downloading the image via HTTP and the image is empty:

$ wget http://example.org/favicon.ico
--2012-05-17 00:13:58--  http://example.org/favicon.ico
Resolving example.org... xx.xx.xx.xxx
Connecting to example.org|xx.xx.xx.xxx|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0 [image/x-icon]
Saving to: `favicon.ico'

    [ <=>                                                                   ] 0           --.-K/s   in 0s      

2012-05-17 00:13:59 (0.00 B/s) - `favicon.ico' saved [0/0]

However, if I scp the image to my local disk and view it, I can view the proper favicon image in the correct format.

Do I have to setup a custom media type or something? If so, how would I do that for a resource such as an image (favicon)? I'm assuming this is not necessary and that rendering a favicon is possible, by default.

EDIT I forgot to mention that I can view the favicon via HTTP when I view it locally (development environment) but when I try to view it remotely (production environment), the favicon doesn't render as it should.

EDIT 2 My rewrite rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !favicon.ico$
    RewriteRule ^ index.php [QSA,L]
</IfModule>

Thanks.

EDIT 3 I've set up a test Lithium app: http://dev.koobi.co/favicon/

The only thing I changed was the layout file and config/bootstrap/libraries.php

As you can see, the icon file doesn't load for this either.

Housni
  • 963
  • 1
  • 10
  • 23
  • have you checked the access/error logs at the remote server? They might give more insights on access rights etc. looks like some config issue – Oerd May 16 '12 at 21:38
  • Yeah, I already did that. When I request for the favicon.ico directly, I get a 304 which is fine. I think it's to do with the way Lithium is serving the .ico file. It seems while editing something, I may have altered this behaviour. I don't edit the core, so it's something in my app...I'm just not sure where to begin debugging to resolve this problem. – Housni May 16 '12 at 21:43
  • 1
    HTTP 304 means "Not modified", try doing a complete refresh or using an incognito/private-browsing window to load the page, then check the logs again for that single request – Oerd May 16 '12 at 21:49
  • Done all that :) Not modified is fine though. It's expected, no? It's curious that this only occurs remotely. I assumed it was environment issue but I set the environment to `production` in config/bootstrap/action.php (locally) and it worked fine...so weird. – Housni May 16 '12 at 22:04
  • 304 is okay, but doesn't get us any further :) 1) check (ls -la) access rights to the favicon.ico file. can http server read it? 2) how does your production .htaccess rewrite urls for favicon.ico? – Oerd May 16 '12 at 22:07
  • As I mentioned in my original post, I can download the file via HTTP so permissions are fine. Rewrite rules also seem fine, they are the same I use locally. I'll add them to my post, as well. – Housni May 16 '12 at 22:25
  • Housni: I read your original post. If your wget gets a 200 OK but zero-length file, then it's not downloaded at all via HTTP :) – Oerd May 16 '12 at 22:27
  • Well, the file is saved as favicon.ico. If it was a permission issue, would it not say that the file does not exist? Seems to me that the file is being served but just not in the right way, which is what I'm trying to figure out. – Housni May 16 '12 at 22:34
  • what if apache has read access to the directory but not to the file? It would list the file as being there, without being able to serve it... this is where i was pointing at on my first comment. Try typing that `ls -la` on the shell, it won't hurt :) – Oerd May 16 '12 at 22:39
  • Sorry Oerd, I should have mentioned I already did this at the beginning. Ownership and permissions for favicon are the same as the CSS files (0644). I've set up a fresh Lithium app: http://dev.koobi.co/favicon/ The favicon.ico doesn't work here, either. – Housni May 17 '12 at 11:02

2 Answers2

0

There is nothing special you have to do. Double check that a valid favicon.ico is available in webroot/ directory. Lithium comes with a favicon you can use.

Mehdi Lahmam B.
  • 2,240
  • 16
  • 22
  • The favicon is valid. As I mentioned in my post, if I download the favicon, I can view it. But via HTTP, the image seems broken. Also, I forgot to mention that I can view the icon via HTTP locally (development env) but not remotely (production env). I'll edit my post and add this info, as well. – Housni May 16 '12 at 20:08
  • What's a good way for me to debug this? Where should I start? – Housni May 16 '12 at 21:08
0

Turns out this was an issue with Hostgator. Lithium was working perfectly. Apparently, Hostgators Apache rules don't allow favicons to be rendered dynamically.

Housni
  • 963
  • 1
  • 10
  • 23