1

I've got for example this url:

http://example.com/team

and I want during this specific time for example: 00:00 to 00:05 (for 5 minutes) to restrict access to it and instead when trying to load /team to be redirected to /home BTW: I am using codeigniter framework.

This is my current htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

I tried with ...

....
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0000
RewriteCond %{TIME_HOUR}%{TIME_MIN} <0005
....

but no luck. Probably I am doing it wrong but I don't get it how it should redirect /teams and such urls?

arserbin3
  • 6,010
  • 8
  • 36
  • 52
MobEn
  • 65
  • 9
  • Your perfect answer it's here http://stackoverflow.com/questions/6119451/page-redirect-after-certain-time-php – SagarPPanchal Sep 11 '14 at 18:02
  • This is for PHP redirection and I want entirely different thing. I want during specific timeframe to restrict access to specific page of my website and instead redirect to another one. – MobEn Sep 11 '14 at 18:08
  • 1
    MobEn I would suggest... Instead of doing it in htaccess.... better you can include the contents depending upon the time. For instance if the time is bw 00:00 to 00:05 then show a msg like Some process is going... we will be back in 5 min. Show some beautiful count down timers. – Indra Kumar S Sep 11 '14 at 18:08
  • But if they already loaded the page before that? – MobEn Sep 11 '14 at 18:11

3 Answers3

2

Giving the other presents rules in your file, you would probably want:

RewriteCond %{TIME_HOUR}%{TIME_MIN} >0000
RewriteCond %{TIME_HOUR}%{TIME_MIN} <0005
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+team [NC]
RewriteRule ^ /home? [R=307,L]

Your current file would look like:

RewriteEngine On

RewriteCond %{TIME_HOUR}%{TIME_MIN} >0000
RewriteCond %{TIME_HOUR}%{TIME_MIN} <0005
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+team [NC]
RewriteRule ^ /home? [R=307,L]

RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

I don't see anything else wrong with your condition it looks just fine and I tested it myself.

The only factor I could see affecting it would be that its using the server time rather than your local time, unless the server is on your computer/local network/local time.

Prix
  • 19,417
  • 15
  • 73
  • 132
  • Now that's something different. Thank you! It works. Probably the `RewriteCond/Rule` has been wrong in the previous one I used to test. Answer accept. – MobEn Sep 11 '14 at 18:39
  • @MobEn mod_rewrite is very picky on how you ordered your rules, so it needs some special attention. – Prix Sep 11 '14 at 18:42
1

I think you area looking for this ...

RewriteCond %{TIME_HOUR} 00
RewriteCond %{TIME_MIN} <05
RewriteRule ^team /home [R=307,L]
cmorrissey
  • 8,493
  • 2
  • 23
  • 27
  • Yeah but simply when I access `www.example.com/team` I am still there and it doesn't redirect to `/home` instead of `/team` – MobEn Sep 11 '14 at 18:07
  • @MobEn this will only work between 12:00 am and 12:05 am – cmorrissey Sep 11 '14 at 18:09
  • I edited it to test it for this current hour and it doesn't work. It still doesn't redirect to /home which is really weird. Am I missing something else? – MobEn Sep 11 '14 at 18:10
  • @MobEn I updated my answer `RewriteRule ^team /home [R=307,L]` I had assumed that there would be something after `/team` such as `/team/my-team/` – cmorrissey Sep 11 '14 at 18:13
  • Yeah, I do have `/team` and additional sub urls such as `/team/view/65` and etc but still doesn't work. Should there be something else? – MobEn Sep 11 '14 at 18:16
  • @MobEn I just tested this it works with out a problem, make sure you have your correct server time for the hour as it may be different depending on your server location – cmorrissey Sep 11 '14 at 18:24
  • @cmorrissey you need to have the same rules he have along with it so you can see why it does not work. – Prix Sep 11 '14 at 18:25
  • @Prix is correct in his answer you need to put this at the top of your Rewite rules and then it will work – cmorrissey Sep 11 '14 at 18:35
0

Try putting one after the other, like this:

RewriteCond %{TIME_HOUR} >00
RewriteCond %{TIME_MIN} < 5
RewriteRule ^dream/?$ /promo.php [L]

See this page:

http://www.askapache.com/htaccess/time_hour-rewritecond-time.html

thiago marini
  • 528
  • 3
  • 11
  • I believe my current time feature works but I don't know how to redirect `/team` to `/home` via the `htaccess`? Could you please give me an example htaccess rule how this should work? Thanks! – MobEn Sep 11 '14 at 18:03