I am utilizing a local install of Apache 2.2.11 and also have setup an alias to some folder over the document root (
alias localhost/fp/ => /www/dirs/friendpages). I must have the ability to redirect demands to "/favicon.ico" to
localhost/fp/favicon.ico instead of
localhost/favicon.ico having a .htaccess file in
localhost/fp. Is possible and when so, wouldso would I actually do that?
The mention of the favicon.ico, will come from the file like the following:
/www/dirs/friendpages/test.htm (localhost/fp/test.htm) =>
<html> <head> <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon"> </head> <body> Page using favicon.ico </body> </html>
I've made several attempts using RewriteRule. For instance,
RewriteRule ^/favicon.ico$ /www/dirs/friendpages/favicon.ico
...but haven't been capable of finding an answer. It seems that I am unclear about just what Pattern is and what Substitution ought to be (given
RewriteRule Pattern Substitution). I am especially unclear about the way i would setup a RewriteRule distinguishing a family member file reference like the one through the link tag above versus. a complete one like "localhost/fp/favicon.ico" (the second clearly not needing a redirection).
I additionally enabled rewrite logging while using following during my
RewriteLogLevel 9 RewriteLog /logs/rewrite.log
...but all I recieve, when loading the above mentioned listed
localhost/fp/test.htm using the above mentioned RewriteRule is:
127.0.0.1 - - [04/Nov/2011:05:09:51 --0700] [localhost/sid#14f44f8][rid#2619268/initial] (3) [perdir /www/dirs/friendpages/] strip per-dir prefix: /www/dirs/friendpages/test.htm -> test.htm 127.0.0.1 - - [04/Nov/2011:05:09:51 --0700] [localhost/sid#14f44f8][rid#2619268/initial] (3) [perdir /www/dirs/friendpages/] applying pattern '^/favicon.ico$' to uri 'test.htm' 127.0.0.1 - - [04/Nov/2011:05:09:51 --0700] [localhost/sid#14f44f8][rid#2619268/initial] (1) [perdir /www/dirs/friendpages/] pass through /www/dirs/friendpages/test.htm
I have found that another way (lacking hardcoding the right reference itself) to offer the preferred outcome is to setup an online host (instead of simply utilizing an alias) but my stomach-feeling is this fact ought to be possible using mod_rewrite and .htaccess... precisely how?
Your RewriteRule looks fine in my experience, I am unsure why it isn't working. (You have
Since /fp has already been aliased to /www/dirs/friendpages, perhaps you should just adjust your link href rather:
Change it out to some relative one:
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
Which will unconditionally make reference to /fp/favicon.ico.
Change it out to suggest clearly to /fp/favicon.ico:
<link href="/fp/favicon.ico" rel="shortcut icon" type="image/x-icon">
In either case, the href points to /fp/favicon.ico, that will resolve to /www/dirs/friendpages/favicon.ico. When the file can there be, then you definitely will not require a rewrite rule for this anymore.
To be sure that the virtual host is much overkill with this problem. A RewriteRule or correct href ought to be all that you should get the favicon.