Skip to main content
ApacheSUSE

Apache – Time based redirections

By October 17, 2013September 12th, 2022No Comments



In this tutorial we are using the Apache HTTPD server on SUSE Linux and we use the example of wanting to display a different support page when the support desk is open to when it is closed. This can be achieved using the rewrite module in apache.

In SUSE we enable the module in /etc/sysconfig/apache2, we add rewrite to the MODULES lines. With that in lace we can then add the conditions and rules that we need.

We have two support pages a day pay that has the live support chat and an out of out or night page that does not have the chat support. In out case the pages are called supportday.html and supportnight.html. As we access the support.html we will be redirected to one of these pages based on the time of day.

Within the httpd.conf, on SUSE we use the default-server-conf I add these lines

ReWriteEngine on
ReWriteCond %{TIME_HOUR}%{TIME_MIN} >0800
ReWriteCond %{TIME_HOUR}%{TIME_MIN} <1800
ReWriteRule ^/support.html$ /supportday.html [R]
ReWriteRule ^/support.html$ /supportnight.html [R]

So if it  between 8 in the morning and 6 at night we deliver the day page, out of hours we deliver the night page