Skip to content

Commit

Permalink
Merge pull request #10 from virtualmin/dev/better-redirect
Browse files Browse the repository at this point in the history
Add working redirect from `/awstats`
  • Loading branch information
jcameron authored Sep 26, 2023
2 parents 8a8bd81 + 89d00b8 commit e995ee9
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions virtual_feature.pl
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,29 @@ sub feature_setup
$d->{'dom'}, $port);
if ($virt) {
my $conf = &apache::get_config();
my $done;
my @sa = &apache::find_directive(
"ScriptAlias", $vconf);
my ($aw) = grep { $_ =~ /^\/awstats/ } @sa;
if (!$aw) {
# Need to add
push(@sa, "/awstats/ $cgidir/");
push(@sa, "/awstats $cgidir/awstats.pl");
&apache::save_directive("ScriptAlias", \@sa,
$vconf, $conf);
$done++;
}
my @rm = &apache::find_directive(
"RedirectMatch", $vconf);
my ($rm) = grep { $_ =~ /^\^\/awstats\$\s+\/awstats/ } @rm;
if (!$rm) {
&apache::save_directive("RedirectMatch",
['^/awstats$ /awstats/'], $vconf, $conf);
$done++;
}
if ($done) {
&flush_file_lines($virt->{'file'});
&virtual_server::register_post_action(
\&virtual_server::restart_apache);
\&virtual_server::restart_apache);
}
}
}
Expand Down Expand Up @@ -485,6 +497,7 @@ sub feature_delete
$d->{'dom'}, $port);
if ($virt) {
my $conf = &apache::get_config();
my $done;
my @sa = &apache::find_directive(
"ScriptAlias", $vconf);
my ($aw) = grep { $_ =~ /^\/awstats/ } @sa;
Expand All @@ -493,9 +506,22 @@ sub feature_delete
@sa = grep { $_ ne $aw } @sa;
&apache::save_directive("ScriptAlias", \@sa,
$vconf, $conf);
$done++;
}
my @rm = &apache::find_directive(
"RedirectMatch", $vconf);
my ($rm) = grep { $_ =~ /^\^\/awstats\$\s+\/awstats\// } @rm;
if ($rm) {
@rm = grep { $_ ne $rm } @rm;
&apache::save_directive(
"RedirectMatch", \@rm,
$vconf, $conf);
$done++;
}
if ($done) {
&flush_file_lines($virt->{'file'});
&virtual_server::register_post_action(
\&virtual_server::restart_apache);
\&virtual_server::restart_apache);
}
}
}
Expand Down

0 comments on commit e995ee9

Please sign in to comment.