Sodaware

Changing the header image every month


One of the things I did with the old design of this blog was to change the header image every month, and it’s something I use on my other website (philnewton.net). I could have done this by uploading a new image every month, but being a programmer I decided to do it a different way.

Using mod_rewrite to change the image

If you’re using an Apache server, you can use something called mod_rewrite to rewrite URLs and do other nifty tricks. I used this to change the image the user saw every month.

I keep all the images in my images folder, and name them according to the month I want them to show. For example, the March image will be called “03-header.jpg”, and the December image “12-header.jpg”. I then use a little mod_rewrite trickery to redirect requests to the correct location. The code looks something like the following:

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^images/header.jpg$ /images/%{TIME_MON}-header.jpg
</ifmodule>

This code is placed in a “.htaccess” file that resides in the html root folder on the server. This is the folder where all the other folders and files are kept. I put it here instead of in the blog folder because WordPress has its own “.htaccess” file which sometimes changed and removed my tweaks.

Using it in the template

You don’t have to make any changes to your html templates, just make sure you link to the image as “header.jpg” and not something like “12-header.jpg”. The server will take care of all the redirection all on its own, and it won’t disturb anyone’s browsing experience.

Related posts:



No Comments

  No comments have been posted yet. Why not be the first?

Leave a Comment

(will not be published)

Tags Allowed: a, abbr, acronym, b, blockquote, code, em, i, strike, strong

Hot Game Downloads

Fatal Hearts

Fatal Hearts

Solve the mysteries behind your dreams in Fatal Hearts!

Mahjong Escape Mahjong Escape
Relax and unwind with Mahjong Escape.
Plantasia Plantasia
Pretty perplexing plant puzzles!

Free Game Downloads | Site Map | Links | Anonymous Feedback | Contact Us

© 2005 — 2012 Sodaware. All rights reserved. About Us | Privacy Policy