Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Search instead for
Did you mean:
Simple web page changes - updating a copyright date
It's that time of the year, when the boss reminds you that you've got to change every single 'Copyright 2006' in the footer of your web pages to 'Copyright 2007'... at midnight, New Year's Eve.
Fear not! With a little TrafficScript, you can celebrate with everyone else and lay the guilt on the boss when you return in the New Year. The trick is to add a TrafficScript response rule that rewrites all of your outgoing web pages, but only after midnight on January 1st:
# First, check the date
if( sys.time.year() < 2007 ) break;
# Now, check it's a web page
$contenttype = http.getResponseHeader( "Content-Type" );
if( ! string.startsWith( $contenttype, "text/html" ) ) break;
The difficult bit is working out which bits of content to rewrite. You can't just change every 2006 to the new date, because there may be lots of dates in the web content that you don't want to change.
For my site, the footer of every page says:
Copyright MySite.com 1995-2006
... and it's in the last 250 bytes of the page (at least, before we insert our Tracking user activity with Google Analytics code).
The following code reads the entire response and rewrites it on the fly. Note that 'http.getResponseBody()' deals with all of the awkward HTTP protocol parsing for you, decompressing compressed responses and reassembling chunked transfers for dynamic applications, so you don't need to downgrade the request to HTTP/1.0, disable keepalives, remove Accept-Encoding headers or anything else: