Can i force a favicon.ico?


#1

lo there all,

i am running two websites on one server. Both use the same code and both
domains point to the same public folder. I use different logos by using
a session variable called session[:domain] that i find with
env_table[‘HTTP_HOST’]

so anyway, both need a different icon to go in the bookmarks and url, i
know this is done with a favicon.ico, but can i force the server to use
one for one domain and a different one for the other domain ?

if so, how ?

thanks


#2

On Jan 17, 2007, at 6:39 PM, Shawn B. wrote:

use
one for one domain and a different one for the other domain ?

If that’s the same Rails application running behind two you could use
rewrite rules per virtual host:

first virtual host

RewriteEngine On
RewriteRule ^favicon.ico$ favicon-vh1.ico [L]

second virtual host

RewriteEngine On
RewriteRule ^favicon.ico$ favicon-vh2.ico [L]

That’s written off the top of my head but you see the idea.

– fxn


#3

ok, cool, where do i write those ?

thanks
shawn


#4

thanks Xavier,
do i still put the icons in /public/images if both sites are
automatically routed to /users/index.rhtml?

thanks


#5

On Jan 17, 2007, at 7:04 PM, Shawn B. wrote:

ok, cool, where do i write those ?

In the configuration of each vhost.

– fxn


#6

ok, i appreciate your help a lot, i am still having trouble with it.
i put both icons just in the /public directory of the rails app.
and here is what i have in the virtual host file for one of the sites

<VirtualHost *>
SetEnv RAILS_ENV production
ServerName www.mysite.com
DocumentRoot /var/www/mysite/public

    <Directory /var/www/mysite/public/>
            Options ExecCGI FollowSymLinks
            AddHandler fcgid-script .fcgi
            Order allow,deny
            Allow from all
            RewriteEngine On
RewriteRule ^favicon.ico$ site_a_icon.ico [L]

            RewriteRule ^$ index.html [QSA]
            RewriteRule ^([^.]+)$ $1.html [QSA]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]
            AllowOverride None
    </Directory>
    ServerSignature On

ErrorDocument 500 /500.html

    ErrorLog /var/log/apache2/pivotrac/error.log
    CustomLog /var/log/apache2/pivotrac/access.log combined
    LogLevel warn

can you see anything that is obvious that i am doing wrong here?
thanks


#7

On Jan 18, 2007, at 1:22 AM, Shawn B. wrote:

can you see anything that is obvious that i am doing wrong here?

Sorry for the delay, I’ve been quite busy lately.

The configuration looks OK to me. I have always put my rewrite rules
outside the Directory section

<VirtualHost …>
<Directory …>

RewriteRule …

but if the FCGI dispatcher is being called the rewrite rules are
working fine.

Did you tell Apache to reload the configuration?

– fxn


#8

On Jan 17, 2007, at 7:39 PM, Shawn B. wrote:

thanks Xavier,
do i still put the icons in /public/images if both sites are
automatically routed to /users/index.rhtml?

That is not its canonical place, but since we are using rewrite rules
you can (tweaking the right-side in the examples I sent before). You
can leave them under public if you want as well.

As you know favicon.ico is normally requested by browsers
automatically. That is, you don’t link to it, except perhaps by a
LINK element like this one in the HEAD of your layout:

Now, if I understand the setup correctly you have two vhosts pointing
to the same Rails application. In particular they share the public
directory which is the root of the problem.

The browser will still ask for

http://www.vhost1.com/favicon.ico

and

http://www.vhost2.com/favicon.ico

respectively when they visit any page on those websites.

The point is that you don’t even have a favicon.ico under public. You
instead have two different .icos somewhere under public and have
rewrite rules fool the browser. Each vhost has a different rewrite
rule that rewrites internally the URL to serve its
corresponding .ico. Perhaps you are not used to this stuff, the
browser won’t know it is getting something called some other thing in
the filsystem of the server, nor that the URL was mangled, /
favicon.ico will be retrieved as if existed.

With this setup both .icos are available using direct URLs since
the document root is shared, but only the corresponding one will be
served as /favicon.ico, which is what we want.

– fxn


#9

never got back to you on this,
but wanted to let you know that your solution worked,
thanks

sk