Apache: time-sensitive redirects, backdoor entry

Friday, April 03 2009 @ 05:02 PM CST

Contributed by: nat

Apache's mod_rewrite can be used to do time-sensitive redirects... handy if you have to make a scheduled change at an inconvenient time. But even better, what if you need to get to the original site? This example also includes a url /backdoor that sets a 15 min cookie, redirects to the main page, and an exclusion to not redirect anyone who has that cookie set. Cool stuff.

    RewriteEngine On
    # Start redirecting after this datetime
    RewriteCond %%%%% >200904040900
    # Don't redirect certain paths
    RewriteCond % !^/favicon.ico
    RewriteCond % !^/webservices
    RewriteCond % !^/backdoor
    # Don't redirect if backdoor cookie is active
    RewriteCond % !backdoor
    # Do the rewrite
    RewriteRule .* http://mynewhostname/ [R,L]

    # Allow back door access to old site (this site) - hit /backdoor and they get a cookie for
    # 15 mins such that they won't be redirected while it is active.
    RewriteRule ^/backdoor http://myoldhostname/ [CO=backdoor:yes:myoldhostname:15:/]

0 comments



/article.php/20090403160259886