Forum Moderators: phranque
in my .htaccess file i assign a default value to a query string variable related to the year:
RewriteRule ^projects/([a-z0-9-]+)/$ metalab2.php?section=projects&sortBy=time&dsAnchor=%{TIME_YEAR}&item=$1 [NC,L]
question: i need to have TIME_YEAR-1, i've tried many ways but they all fail. what's the correct method of getting the calculation to be performed?
thanks for your help!
Alex
If you have a limited number of years you must handle, you can do a lookup-table-based string substitution rather than numerical subtraction:
RewriteCond %{TIME_YEAR}<>1996 ^1997<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>1997 ^1998<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>1998 ^1999<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>1999 ^2000<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2000 ^2001<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2001 ^2002<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2002 ^2003<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2003 ^2004<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2004 ^2005<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2005 ^2006<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2006 ^2007<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2007 ^2008<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2008 ^2009<>(.+)$ [OR]
RewriteCond %{TIME_YEAR}<>2009 ^2010<>(.+)$
RewriteRule ^projects/([a-z0-9\-]+)/$ metalab2.php?section=projects&sortBy=time&dsAnchor=[b]%1[/b]&item=$1 [NC,L]
Note that "<>" has no meaning whatsoever to mod_rewrite: It is used only as a 'boundary marker' between the concatenated RewriteCond strings. You can leave it out if you prefer, or use any other "harmless and rare" character or character sequence. I chose "<>" simply to imply concatenation.
The first RewriteCond basically says, "If the current year string is 1997, put the string value 1996 into the %1 variable."
Jim