site is called twice?

后端 未结 5 374
后悔当初
后悔当初 2020-12-12 05:13

My Problem is, that my php site is called twice. But i don\'t know why. in my access-log i also get two entries if i reload:

127.0.0.12 - - [13/Oct/2010:20:4         


        
相关标签:
5条回答
  • 2020-12-12 05:30

    The second call is the browser's attempt to get the favorites icon (favicon.ico). Apparently you have one, since your server returned status 200, so not a problem.

    0 讨论(0)
  • 2020-12-12 05:38

    Your site is called twice indeed, but your index page is only called once. The other request is looking for favicon.ico, i.e. the icon your browser will display in the tab/window your page resides in.

    EDIT: @TokenMacGuy's comment below is probably right on the money.

    0 讨论(0)
  • 2020-12-12 05:39

    That's totally normal, because that second second call is made to retrieve favicon, a small icon which usually appears on a tab in the browser. Even if you don't have it, browsers will usually try to get it.

    0 讨论(0)
  • 2020-12-12 05:47

    the reason, why my index.php loaded, twice was another (so not the favicon): in my .htaccess I had my

    ErrorDocument 404
    

    command at the end of the file. putting it before the

    RewriteEngine On
    

    did the trick.


    helle's answer led me to another helpful (quite simple) idea: to find out, which request is calling your index.php, simply put the following at the beginning of it:

    file_put_contents('stats/stats.txt', $_SERVER['REQUEST_URI'], FILE_APPEND);
    
    0 讨论(0)
  • 2020-12-12 05:50

    this is one of Chrome's known quirks. It re-requests favicon.ico on every single page call (even view source!) Other browsers cache it. Nothing you need to be concerned about. Just make sure the file is there to avoid the 404 overhead! - by @chigley

    UPDATE

    after thinking about the 404 issue i found an other resolution.

    add this line into your .htaccess file:

    RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC] 
    

    OLD and DEPRECATED

    hm to be able to accept an answer in this thread... I found a rather easy way to not react on that request ... but it is for testreason only

    I just put this in the first php line of my index file:

    if($_SERVER['REQUEST_URI'] == "/favicon.ico") return false;
    

    even if the favicon.ico is there this will help you avoid double entries in your error-log files. it makes it much more readable then.


    you have to know that i am using a .htaccess file like this:

    Options +FollowSymLinks
    IndexIgnore */*
    # Turn on the RewriteEngine
    RewriteEngine On
    RewriteBase /
    #  Rules
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC] 
    RewriteRule . index.php
    
    0 讨论(0)
提交回复
热议问题