Why am I getting error for apple-touch-icon-precomposed.png

后端 未结 11 1758
梦谈多话
梦谈多话 2020-11-29 16:06

I have created a new rails3 project but I am seeing following logs many times in my server logs. Why I am getting these request and how can I avoid these?

相关标签:
11条回答
  • 2020-11-29 16:29

    Note that this can happen even when the user has NOT bookmarked the site to their iOS home screen - for example, any time you open a page using Chrome for iOS, it does a GET "/apple-touch-icon-precomposed.png".

    I've handled this and other non-HTML 404 requests in my ApplicationController as follows:

    respond_to do |format|
      format.html { render :template => "error_404", :layout => "errors", :status => 404 }
      format.all { render :nothing => true, :status => 404 }
    end
    

    The format.all response takes care of images such as this PNG file (which does not exist for my site).

    0 讨论(0)
  • 2020-11-29 16:34

    If you ended here googling, this is a simple configuration to prevent this error full the web server logs:

    Apache virtualhost

    Redirect 404 /apple-touch-icon-precomposed.png
    <Location /apple-touch-icon-precomposed.png>
        ErrorDocument 404 "apple-touch-icon-precomposed does not exist"
    </Location>
    

    Nginx server block:

    location =/apple-touch-icon-precomposed.png {
            log_not_found off;
            access_log off;
    }
    

    PS: Is possible you want to add apple-touch-icon.png and favicon.ico too.

    0 讨论(0)
  • 2020-11-29 16:35

    Simply create zero-sized files called the appropriate names.

    The request will be satisfied with no additional data transfer nor further logging lines.

    0 讨论(0)
  • 2020-11-29 16:36

    An alternative solution is to simply add a route to your routes.rb

    It basically catches the Apple request and renders a 404 back to the client. This way your log files aren't cluttered.

    # routes.rb at the near-end
    match '/:png', via: :get, controller: 'application', action: 'apple_touch_not_found', png: /apple-touch-icon.*\.png/
    

    then add a method 'apple_touch_not_found' to your application_controller.rb

    # application_controller.rb
    def apple_touch_not_found
      render  plain: 'apple-touch icons not found', status: 404
    end
    
    0 讨论(0)
  • 2020-11-29 16:39

    I guess apple devices make those requests if the device owner adds the site to it. This is the equivalent of the favicon. To resolve, add 2 100×100 png files, save it as apple-touch-icon-precomposed.png and apple-touch-icon.png and upload it to the root directory of the server. After that, the error should be gone.

    I noticed lots of requests for apple-touch-icon-precomposed.png and apple-touch-icon.png in the logs that tried to load the images from the root directory of the site. I first thought it was a misconfiguration of the mobile theme and plugin, but found out later that Apple devices make those requests if the device owner adds the site to it.

    Source: Why Webmasters Should Analyze Their 404 Error Log (Mar 2012; by Martin Brinkmann)

    0 讨论(0)
提交回复
热议问题