Quantcast
Channel: Lecciones Prácticas
Viewing all articles
Browse latest Browse all 33

[SOLVED] Fix apple-touch-icon 404 errors

$
0
0

Some days ago I was checking AWStats reports in my Invenio site and I noticed some (unexpected) 404 errors. Visitors were trying to load URL’s like /iphone or /m and some images which were not linked in my site… (‘apple-touch-icon.png‘ and similar filenames).

apple-touch-icon-precomponsed.png 404 fix

This has to do with some bots coming along, assuming that my site includes a mobile version, and then trying its hand at guessing the location. In the common request-set listed above, we see the bot looking first for an “apple-touch icon,” and then for mobile content in various directories.

But what about thoses images? Take a read at: http://www.computerhope.com/jargon/a/appletou.htm

Similar to the Favicon, the apple-touch-icon.png is a file used for a web page icon on the Apple iPhone, iPod Touch, and iPad. When someone bookmarks your web page or adds your web page to their home screen this icon is used. If this file is not found these Apple products will use the screen shot of the web page, which often looks like no more than a white square.

This file should be saved as a .png, have dimensions of 57 x 57, and be stored in your home directory, unless the path is specified in the HTML using the below code.

When this file is used, by default, the Apple product will automatically give the icon rounded edges and a button-like appearance.

I wanted to fix this, so I began by testing if mod_rewrite was enabled…

[root@aneto www]# grep -R "mod_rewrite" /etc/httpd/conf/
/etc/httpd/conf/httpd.conf:LoadModule rewrite_module modules/mod_rewrite.so

The LoadModule line is uncommented, so it is enabled.

Next step would be to try a basic redirection to test mod_rewrite.

Edit $PATH_TO_INVENIO/etc/apache/invenio-apache-vhost.conf and added this lines in the VirtualHost part.

<ifmodule mod_rewrite.c>
           RewriteEngine  On
           RewriteLog "/home/apache/rewrite.log"
           RewriteLogLevel 9
           RewriteRule old.html bar.html [R]
</ifmodule>

Then restart apache…

[root@aneto ~]# /etc/init.d/httpd  restart

Then open your browser and test the redirection. You should be redirected and the /home/apache/rewrite.log should log that redirection…

[root@aneto ~]# tail -n20 -f /home/apache/rewrite.log
 
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (2) init rewrite engine with requested uri /old.html
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (3) applying pattern 'old.html' to uri '/old.html'
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (2) rewrite '/old.html' -> 'bar.html'
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (2) explicitly forcing redirect with http://155.210.47.102/bar.html
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (1) escaping http://155.210.47.102/bar.html for redirect
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b689442f0c8][rid#2b68947a7380/initial] (1) redirect to http://155.210.47.102/bar.html [REDIRECT/302]
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b46e1df80d8][rid#2b46eac962e0/initial] (2) init rewrite engine with requested uri /bar.html
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b46e1df80d8][rid#2b46eac962e0/initial] (3) applying pattern 'old.html' to uri '/bar.html'
155.210.47.93 - - [05/Jul/2013:12:21:06 +0200] [155.210.47.102/sid#2b46e1df80d8][rid#2b46eac962e0/initial] (1) pass through /bar.html

Now that we know that mod_rewrite is working properly, lets add some code to forbid some URL patterns (more refences)…

<ifmodule mod_rewrite.c>
           RewriteEngine  On
           RewriteLog "/home/apache/rewrite.log"
           RewriteLogLevel 9
           #RewriteRule old.html bar.html [R]
           RewriteCond %{REQUEST_URI} /iphone/?$ [NC,OR]
           RewriteCond %{REQUEST_URI} /mobile/?$ [NC,OR]
           RewriteCond %{REQUEST_URI} /mobi/?$ [NC,OR]
           RewriteCond %{REQUEST_URI} /m/?$ [NC]
           RewriteRule (.*) - [F,L]
</ifmodule>

This technique is useful for saving bandwidth and server resources, not just for non-existent mobile-ish requests, but also for any resource that you would like to block – just add a RewriteCond with the target character string of your choice. Hopefully this technique will help you run a cleaner, safer, and more secure website.

Now, what to do with those apple-touch-icon-precomposed.png and similar images which are ending in 404 errors?

First read full Apple documentation about this issue.

Then you can fix it several ways:

1) Search for those images and download them to /soft/cds-invenio/var/www/

cd /soft/cds-invenio/var/www/
wget http://gwt-touch.googlecode.com/svn-history/r86/trunk/demo-ipad-settings/war/apple-touch-icon-precomposed.png

Or you can create some personalized images using online services like http://iconifier.net/

Captura de pantalla 2013-07-05 a la(s) 14.32.55

And you’re ready to go! Logs won’t show those ugly 404 errors from now on and visitors using iphone’s will be happier :)

The post [SOLVED] Fix apple-touch-icon 404 errors appeared first on Lecciones Prácticas.


Viewing all articles
Browse latest Browse all 33

Trending Articles