我想根据一组条件设置多个规则,如下所示:
仅适用于2016年4月13日上午5:00>晚上11:00
仅当源IP在范围内时适用
如果两个都适用,则重定向2x页
RewriteCond %{TIME} >20160413050000 [NC]
RewriteCond %{TIME} <20160414230000 [NC]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.10[3-9] [OR]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.11[0-1] [OR]
RewriteCond %{REMOTE_ADDR} ^89\.197\.6\.236
RewriteRule ^confirm.html$ /confirm-logos.html [R=307,L,QSA]
RewriteRule ^blacklist.html$ /blacklist-logos.html [R=307,L,QSA]时间规则有效,IP范围有效,但当我有多个这样的块时,它们似乎会冲突。对于我想要实现的目标,上述方法是否正确?
发布于 2016-04-12 00:18:42
RewriteCond指令定义规则条件。RewriteRule指令之前可以有一个或多个RewriteCond。然后,仅当URI的当前状态与其模式匹配并且满足这些条件时,才使用以下规则。http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond
您可以使用:
RewriteCond %{TIME} >20160413050000 [NC]
RewriteCond %{TIME} <20160414230000 [NC]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.10[3-9] [OR]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.11[0-1] [OR]
RewriteCond %{REMOTE_ADDR} ^89\.197\.6\.236
RewriteRule ^confirm.html$ /confirm-logos.html [R=307,L,QSA]
RewriteCond %{TIME} >20160413050000 [NC]
RewriteCond %{TIME} <20160414230000 [NC]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.10[3-9] [OR]
RewriteCond %{REMOTE_ADDR} ^212\.74\.117\.11[0-1] [OR]
RewriteCond %{REMOTE_ADDR} ^89\.197\.6\.236
RewriteRule ^blacklist.html$ /blacklist-logos.html [R=307,L,QSA]或者,如果您有许多规则,则颠倒测试:
RewriteCond %{TIME} <20160413050000 [NC,OR]
RewriteCond %{TIME} >20160414230000 [NC]
RewriteCond %{REMOTE_ADDR} !^212\.74\.117\.10[3-9]
RewriteCond %{REMOTE_ADDR} !^212\.74\.117\.11[0-1]
RewriteCond %{REMOTE_ADDR} !^89\.197\.6\.236
RewriteRule ^ - [L]
RewriteRule ^confirm.html$ /confirm-logos.html [R=307,L,QSA]
RewriteRule ^blacklist.html$ /blacklist-logos.html [R=307,L,QSA]https://stackoverflow.com/questions/36551881
复制相似问题