WP-Mix

A fresh mix of code snippets and tutorials

.htaccess for cookie-less image domain

Here is a choice collection of .htaccess directives that I use when hosting images on a subdomain. When doing so, it’s best for performance to make sure the domain or sub-domain is “cookie-less”, so there is no time wasted sending cookie data back and forth between the server and client. Other optimizations are included to enhance performance.

AddDefaultCharset UTF-8
ServerSignature Off
Options -Indexes
FileETag none

<IfModule mod_headers.c>
	Header unset ETag
	Header unset Cookie
	Header unset Set-Cookie
</IfModule>

<IfModule mod_rewrite.c>
	RewriteEngine On
</IfModule>

<IfModule mod_expires.c>
	ExpiresActive on
</IfModule>

<FilesMatch "\.(ico|jpg|jpeg|jpe|png|gif)$">
	ExpiresDefault "access plus 2 years"
</FilesMatch>

<IfModule mod_expires.c>
	ExpiresByType image/x-icon "access plus 2 years"
	ExpiresByType image/ico "access plus 2 years"
	ExpiresByType image/gif "access plus 2 years"
	ExpiresByType image/jpg "access plus 2 years"
	ExpiresByType image/jpe "access plus 2 years"
	ExpiresByType image/jpeg "access plus 2 years"
	ExpiresByType image/png "access plus 2 years"
</IfModule>

These directives assume that only images will be hosted on the domain/subdomain. If other types of resources are available, you may need to modify the current directives to add support.

Learn more

.htaccess made easy