开发者

redirect using htaccess based on date in php

I want to redirect to Page not found.php page if the date is less then some date.

for example,

www.example.com/index.php?dt='2011-03-11'.

this index page fetches data in db based on date for display. if the passed date is less than some date it should redirect to pagenotfou开发者_JS百科nd.php . how can i do this using htaccess?

Thanks.


You'll have to test for the date, in your PHP script ; and redirect, using the header() function :

if ($_GET['dt'] <= date('Y-m-d')) {
    // Redirect to your other page
    header('Location: http://www.yoursite.com/page-not-found.php');
    exit();
}


Note : before doing this test, it might be interesting to :

  • Ensure that $_GET['dt'] exists, using isset()
  • Verify if it contains something that's a valid date


Why does it need to be via .htaccess? Seems like this logic is better put in the script itself:

if ($date < $somedate) {
    header('HTTP/1.1 302 Found');
    header('Location: http://www.example.com/error.php');
    exit;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜