WordPress Code Snippets

A fresh mix of code snippets and tutorials

.htaccess for Apple Touch Icons

93

Devices and bots are often searching for different versions of the Apple Touch Icon. Here is a quick slice of .htaccess to redirect all apple-icon requests to apple.png.

Instead of dealing with countless 404 errors for missing apple icons such as apple-touch-icon-precomposed.png and apple-touch-icon-72x72.png, upload a single apple.png file and add this snippet to your root .htaccess file:

RedirectMatch 301 /apple-touch-icon(.*)?.png /apple.png

Note: the apple.png file should be uploaded to the site’s root directory.

Update

I changed the name of my apple icon from apple.png to apple-touch-icon.png. Here is the new .htaccess rule that I use to redirect all requests for apple icons:

RedirectMatch 301 (?i)/apple(-touch-icon-.*)?.png /apple-touch-icon.png

This will redirect all requests for apple.png and/or any variation of apple-touch-icon-whatever.png to the file, apple-touch-icon.png. Note that apple-touch-icon.png should be located in the root directory of your site. Also note that this technique is case-insensitive, as instructed by the prepended (?i) modifier.

Examples

To see some examples of this code in action, click the following links:

Learn more

.htaccess made easy


Show Support

Like our new Facebook Page to show support!