Search code examples
phpfaviconlithium

How do I render favicons in Lithium?


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.


Solution

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