Forum Moderators: phranque

Message Too Old, No Replies

.htaccess favicon.ico

         

quali74

6:29 pm on Nov 7, 2010 (gmt 0)

10+ Year Member



hello,

I have built a site whose URL are as follow : [mydomain...] , so for example: [mydomain...]

the .htaccess I have is as follow:
RewriteEngine on
Options +FollowSymlinks

DirectoryIndex index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?mode=$1 [L,QSA]


I have setup my site so my index.php reads the first parameter of the URL and gets in the DB the related data.

Now, ... the problem. I have setup my site to email me if an error occurs and I receive strange messages indicating me that 'favicon.ico'
, images/clear.gif, or othe images are passed to the PHP. Is there anybody who understand what is happening and how I could stopped those files to be processed by the index.php?

thanks

sublime1

2:54 am on Nov 13, 2010 (gmt 0)

10+ Year Member



The rewrite rules look fine. I would bet, given the cases you specify, that the actual files are not there.

favicon.ico will be looked for in a number of different locations, depending on your HTML and also on the browser. Same could be true with cheezy image files used to help force layout -- ah, the bad old days.

However there's another possibility: this is an internal rewrite -- once the rewrite is complete, apache will check again, so if something changes the directory (in index.php or downstream), it might be looking in the wrong place.

Can you ensure that the files are not actually in the location specified? If so, which location(s) are specified in the error message.

Tom

quali74

6:07 pm on Nov 13, 2010 (gmt 0)

10+ Year Member



it looks for favicon.ico at the root of the site. The file is not there and is is located in a different folder. Its name can be anything as I use this code:

<link rel="icon" href="/myuploadedfiles/{$favicon}" type="image/x-icon">
<link rel="shortcut icon" href="/myuploadedfiles/{$favicon}" type="image/x-icon">

sublime1

10:01 pm on Nov 13, 2010 (gmt 0)

10+ Year Member



I have the same declaration on my pages for favicon.ico that is not found at the web root (mine is on a different server). It seems like about 20% of browsers ignore it and look for the icon in the document root. I gave up and put a copy at /.

That doesn't explain the clear.gif issue, however as that is not special in any way.

g1smd

10:28 pm on Nov 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Speed up the .htaccess rules a LOT by adding a preceding negative-match RewriteCond that excludes many types of files from even proceeding as far as the very slow -f and -d "exists" checks.

jdMorgan

11:37 pm on Nov 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should solve both problems -- prevent favicon and other 'filetype' requests from being rewritten to your script, and speed up your server as well:

RewriteCond $1 !^([^/]+/)*[^/.]+$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?mode=$1 [QSA,L]

The first RewriteCond now causes the rule to be skipped (along with the very slow file- and directory-exists checks) if the requested URL-path ends with a slash or if the final URL-path-part contains a period, indicating that this request is for a 'real' file.

You may need either a more- or less-specific exclusion, depending on the exact details of your site and the URLs that you use.

Jim