Doug
Doug

Reputation: 821

Using .htaccess to redirect requests for updated cached files

A client has changed their branding slightly so I need to update the CSS and favicon. Favicons, particularly, seem to be very strongly cached so, to stop the client from thinking the work hasn't been done, I would like to add a rule in the .htaccess that instructs something like...

"Take the request for /favicon.ico and instead serve up /favicon2.ico"

...and a similar rule for the CSS if possible.

I'm pretty sure I've seen this done before but I failed to make a note of it.

Upvotes: 0

Views: 42

Answers (1)

nwellnhof
nwellnhof

Reputation: 33618

Redirects won't help you with cached requests where the client doesn't make a request to the server at all. The best solution is to change your HTML pages and add a query string with a version number to your favicons and other resources:

<link rel="shortcut icon" href="/favicon.ico?v=1" />
<link rel="stylesheet" type="text/css" href="/style.css?v=1" />

Then you can update the version number whenever the resource changes.

Upvotes: 1

Related Questions