Question

I want certain rewrites to fire during the month of September, and then different rewrites to happen in the month of October.

I've set up two blocks of rewrites and used RewriteConds, as below. The problem is that the second block doesn't seem to fire.

Is it the Skip in the first block that doesn't work? Or is there some other bug in my .htaccess code? If I comment the first block out, the second block of rewrites work fine. Is it something incorrect about my implementation of the [S] skip flag?

# HANDLE PROMOTIONAL IMAGES FOR OCTOBER 2013
RewriteCond %{TIME_MON} !10 [OR]
RewriteCond %{TIME_YEAR} !2013
RewriteRule .* - [S=4]
RewriteRule ^a_750  a_750-0913.png [L,NC]
RewriteRule ^bbb    bbb_750-0913.png [L, NC]
RewriteRule ^ccc    ccc_750-0913.png [L,NC]
RewriteRule ^dnce.png   dnce_750-0913.png [L, NC]

# HANDLE PROMOTIONAL FUNNEL IMAGES FOR SEPTBMER 2013
RewriteCond %{TIME_MON} !09 [OR]
RewriteCond %{TIME_YEAR} !2013
RewriteRule .* - [S=14]
RewriteRule ^a_750  a_1000-1013.png [L,NC]
RewriteRule ^ener   ener_1000-1013.jpg [L,NC]
RewriteRule ^ethi   ethi_1000-1013.png [L,NC]
RewriteRule ^cred   cred_1000-1013.png [L,NC]
RewriteRule ^edn    edn_1000-1013.png [L,NC]
RewriteRule ^GE_f   GE_f_1000-1013.jpg [L,NC]
RewriteRule ^npc    npc_1000-1013.png [L,NC]
RewriteRule ^nwg    nwg_1000-1013.png [L,NC]
RewriteRule ^pssp   pssp_1000-1013.png [L,NC]
RewriteRule ^pris   pris_1000-1013.png [L,NC]
RewriteRule ^Sier   sier_1000-1013.png [L,NC]
RewriteRule ^uno    uno_1000-1013.jpg [L,NC]
RewriteRule ^wtw    wtw_1000-1013.jpg [L,NC]
RewriteRule ^wke    wke_1000-1013.png [L,NC]
Was it helpful?

Solution

  1. You have syntax errors in your first block as no space is allowed before NC
  2. Regex Problem 1: Make sure to end matching pattern in RewriteRule using $ otherwise ^bbb will match again and again.
  3. Regex Problem 2: Make sure to enclose months and year in RewriteCond using ^ and $ otherwise unwanted year/month will match.

With all these corrections here is the code that should work for you:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# HANDLE PROMOTIONAL IMAGES FOR OCTOBER 2013
RewriteCond %{TIME_MON} !^10$ [OR]
RewriteCond %{TIME_YEAR} !^2013$
RewriteRule ^ - [S=4]
RewriteRule ^a_750/?$ a_750-0913.png [L,NC]
RewriteRule ^bbb/?$ bbb_750-0913.png [L,NC]
RewriteRule ^ccc/?$ ccc_750-0913.png [L,NC]
RewriteRule ^dnce\.png$ dnce_750-0913.png [L,NC]

# HANDLE PROMOTIONAL FUNNEL IMAGES FOR SEPTBMER 2013
RewriteCond %{TIME_MON} !^09$ [OR]
RewriteCond %{TIME_YEAR} !^2013$
RewriteRule ^ - [S=14]
RewriteRule ^a_750/?$ a_1000-1013.png [L,NC]
RewriteRule ^ener/?$ ener_1000-1013.jpg [L,NC]
RewriteRule ^ethi/?$ ethi_1000-1013.png [L,NC]
RewriteRule ^cred/?$ cred_1000-1013.png [L,NC]
RewriteRule ^edn/?$ edn_1000-1013.png [L,NC]
RewriteRule ^GE_f/?$ GE_f_1000-1013.jpg [L,NC]
RewriteRule ^npc/?$ npc_1000-1013.png [L,NC]
RewriteRule ^nwg/?$ nwg_1000-1013.png [L,NC]
RewriteRule ^pssp/?$ pssp_1000-1013.png [L,NC]
RewriteRule ^pris/?$ pris_1000-1013.png [L,NC]
RewriteRule ^Sier/?$ sier_1000-1013.png [L,NC]
RewriteRule ^uno/?$ uno_1000-1013.jpg [L,NC]
RewriteRule ^wtw/?$ wtw_1000-1013.jpg [L,NC]
RewriteRule ^wke/?$ wke_1000-1013.png [L,NC]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top