Daily Image - Show Tomorrow

Using mod_rewrite to handle various content issues

Daily Image - Show Tomorrow

Postby jazzylee » Tue Apr 10, 2007 2:25 pm

I'm using modrewrite to show different images using the same image url dependent on date. Using the following code.

RewriteRule ^pic.gif$ pic-%{TIME_MON}-%{TIME_DAY}.gif

then create files named by date like
pic-03-08.gif
pic-03-09.gif
pic-03-10.gif

This is working just fine, but now I'm wondering if I can alter this to show tomorrow's image? Sure, one clunky way would be to create another file set using different dates. and that may end up being easier than develop a set of rules for different months etc.
jazzylee
 
Posts: 12
Joined: Tue Apr 10, 2007 2:11 pm

Postby richardk » Tue Apr 10, 2007 3:26 pm

This is the only way i could think of doing it with mod_rewrite (it should work but is untested)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Moving to next month. (mm/dd)
# January:   01/31 --> 02/01
RewriteCond %{TIME_MON}-%{TIME_DAY}-02-01 ^01-31-(02-01)$ [OR]
# Feburary:  02/29 --> 03/01 (leap year)
RewriteCond %{TIME_MON}-%{TIME_DAY}-03-01 ^02-29-(03-01)$ [OR]
# Feburary:  02/28 --> 03/01 (not leap year)
RewriteCond %{TIME_MON}-%{TIME_DAY}-03-01 ^02-28-(03-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-04-01 ^03-31-(04-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-05-01 ^04-30-(05-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-06-01 ^05-31-(06-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-07-01 ^06-30-(07-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-08-01 ^07-31-(08-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-09-01 ^08-31-(09-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-10-01 ^09-30-(10-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-11-01 ^10-31-(11-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-12-01 ^11-30-(12-01)$ [OR]
RewriteCond %{TIME_MON}-%{TIME_DAY}-01-01 ^12-31-(01-01)$
RewriteRule ^pic\.gif$ /pic-%1.gif [L]

# Add one to days. (dd)
# 09 to 10
RewriteCond %{TIME_DAY}-10 ^09-(10)$ [OR]
RewriteCond %{TIME_DAY}-10 ^19-(20)$ [OR]
RewriteCond %{TIME_DAY}-10 ^29-(30)$
RewriteRule ^pic\.gif$ /pic-%{TIME_MON}-%1.gif [L]

# Add one to days. (dd)
# 10 to 11 or 20 to 21 or 30 to 31
RewriteCond %{TIME_DAY}-1 ^([0-9])0-(1)$ [OR]
RewriteCond %{TIME_DAY}-2 ^([0-9])1-(2)$ [OR]
RewriteCond %{TIME_DAY}-3 ^([0-9])2-(3)$ [OR]
RewriteCond %{TIME_DAY}-4 ^([0-9])3-(4)$ [OR]
RewriteCond %{TIME_DAY}-5 ^([0-9])4-(5)$ [OR]
RewriteCond %{TIME_DAY}-6 ^([0-9])5-(6)$ [OR]
RewriteCond %{TIME_DAY}-7 ^([0-9])6-(7)$ [OR]
RewriteCond %{TIME_DAY}-8 ^([0-9])7-(8)$ [OR]
RewriteCond %{TIME_DAY}-9 ^([0-9])8-(9)$
RewriteRule ^pic\.gif$ /pic-%{TIME_MON}-%1%2.gif [L]


But you may still want to not use mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jazzylee » Tue Apr 10, 2007 3:52 pm

Thanks, I'll try that out.

The reason I'm using mod rewrite for the daily is to offer a changing image that is hosted on my server. So my visitors take my link code and use it wherever.

Come to think of it, I would probably only use the "tomorrows image" on my pages to promote. SO I could use a php solution for that part.

I'm assuming the reason I may not want to use mod_rewrite would be the extra processor load?
jazzylee
 
Posts: 12
Joined: Tue Apr 10, 2007 2:11 pm

Postby jazzylee » Tue Apr 10, 2007 6:35 pm

Thanks again. With just a little fiddling with the paths it worked. Well today anyway. :)
jazzylee
 
Posts: 12
Joined: Tue Apr 10, 2007 2:11 pm

Postby jazzylee » Thu Apr 19, 2007 4:30 am

I had the first error today 4/19 not showing the image for 4/20
jazzylee
 
Posts: 12
Joined: Tue Apr 10, 2007 2:11 pm

Postby richardk » Fri Apr 20, 2007 9:19 am

Code: Select all
# Add one to days. (dd)
# 09 to 10
RewriteCond %{TIME_DAY}-10 ^09-(10)$ [OR]
RewriteCond %{TIME_DAY}-10 ^19-(20)$ [OR]
RewriteCond %{TIME_DAY}-10 ^29-(30)$
RewriteRule ^pic\.gif$ /pic-%{TIME_MON}-%1.gif [L]

should be
Code: Select all
# Add one to days. (dd)
# 09 to 10
RewriteCond %{TIME_DAY}-10 ^09-(10)$ [OR]
RewriteCond %{TIME_DAY}-20 ^19-(20)$ [OR]
RewriteCond %{TIME_DAY}-30 ^29-(30)$
RewriteRule ^pic\.gif$ /pic-%{TIME_MON}-%1.gif [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jazzylee » Fri Apr 20, 2007 3:50 pm

Thanks. This is my favorite site feature at the moment. :)
jazzylee
 
Posts: 12
Joined: Tue Apr 10, 2007 2:11 pm


Return to Content

Who is online

Users browsing this forum: No registered users and 0 guests

cron