Forum: Ruby on Rails can i force a favicon.ico ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-01-17 18:39
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
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-01-17 18:52
(Received via mailing list)
On Jan 17, 2007, at 6:39 PM, Shawn Bright 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
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-01-17 19:04
ok, cool, where do i write those ?

thanks
shawn
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-01-17 19:28
(Received via mailing list)
On Jan 17, 2007, at 7:04 PM, Shawn Bright wrote:

> ok, cool, where do i write those ?

In the configuration of each vhost.

-- fxn
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-01-17 19:39
thanks Xavier,
do i still put the icons in /public/images if both sites are
automatically routed to /users/index.rhtml?

thanks
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-01-17 21:38
(Received via mailing list)
On Jan 17, 2007, at 7:39 PM, Shawn Bright 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:

   <!-- following the guidelines in http://en.wikipedia.org/wiki/
Favicon -->
   <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

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
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 Shawn Bright (nephish)
on 2007-01-18 01:22
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
</VirtualHost>

can you see anything that is obvious that i am doing wrong here?
thanks
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-01-21 01:12
(Received via mailing list)
On Jan 18, 2007, at 1:22 AM, Shawn Bright 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 ...>
     </Directory>
     RewriteRule ...
     ...
   </VirtualHost>

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

Did you tell Apache to reload the configuration?

-- fxn
500e92cfb666d6757c317a5df7c7e28d?d=identicon&s=25 nephish (Guest)
on 2007-04-08 13:23
never got back to you on this,
but wanted to let you know that your solution worked,
thanks

sk
This topic is locked and can not be replied to.