Time Dependant Rewriting

Discussion in 'Apache' started by amcfarlane, Dec 18, 2007.

  1. #1
    Hi folks...

    I've been trying to figure how to use mod_rewrite to force all access of a site to a particular page during certain times.

    What I'm trying to do is ensure that anyone attempting to access any html document during a particular period will *only* see an off-line notice.

    The rules I have are:

    RewriteCond %{TIME_HOUR}%{TIME_MIN} >0230
    RewriteCond %{TIME_HOUR}%{TIME_MIN} <0330
    RewriteRule ^.*$ /offline.html [F,L]

    Now obviously, this doesn't work as attempting to access offline.html will itself result in a redirection taking place.

    Any suggestions?
     
    amcfarlane, Dec 18, 2007 IP
  2. amcfarlane

    amcfarlane Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To answer myself:

    RewriteCond %{TIME_HOUR}%{TIME_MIN} >0230
    RewriteCond %{TIME_HOUR}%{TIME_MIN} <0330
    RewriteCond %{SCRIPT_FILENAME} !offline\.html$ [NC]
    RewriteRule ^.*$ http://www.domain.tld/offline.html [R=302,L]

    Works for me
     
    amcfarlane, Dec 18, 2007 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    joebert, Dec 19, 2007 IP
  4. Seiya

    Seiya Peon

    Messages:
    4,666
    Likes Received:
    404
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You'd definitely want to do this with php or asp or whatever... :confused:
     
    Seiya, Dec 19, 2007 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    Why on earth would you want to do that ?

    That would be like letting someone into a closed store just so they can read the sign that says it's closed & then forcing them to leave.
     
    joebert, Dec 19, 2007 IP