1

我希望在 9 月份进行某些重写,然后在 10 月份进行不同的重写。

我已经设置了两个重写块并使用了 RewriteConds,如下所示。问题是第二个块似乎没有触发。

是不是第一个块中的跳过不起作用?或者我的 .htaccess 代码中是否还有其他错误?如果我将第一个块注释掉,第二个重写块就可以正常工作。我的 [S] 跳过标志的实现是否有问题?

# 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]
4

1 回答 1

1
  1. 您的第一个块中有语法错误,因为之前不允许有空格NC
  2. 正则表达式问题1:确保在RewriteRule使用中结束匹配模式,$否则^bbb会一次又一次地匹配。
  3. 正则表达式问题 2:确保在RewriteCond使用中包含月份和年份^$否则不需要的年份/月份将匹配。

通过所有这些更正,这里的代码应该适合您:

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]
于 2013-09-26T08:53:08.960 回答