+my $koha_db_version = C4::Context->preference('Version');
+my $kohaversion = C4::Context::KOHAVERSION;
+$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
+
+#warn "db: $koha_db_version, koha: $kohaversion";
+
+if ( $kohaversion > $koha_db_version or C4::Context->preference('OpacMaintenance') ) {
+ output_html_with_http_headers $input, '', $template->output;
+}
+else {
+ print $input->redirect("/cgi-bin/koha/opac-main.pl");
+}