1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser';
use Encode;
use File::Basename 'basename';
use FindBin;
use HTML::Element;
use Template;
my $q = CGI->new;
my $tt = Template->new(
INCLUDE_PATH => "$FindBin::Bin/templates",
FILTERS => {
literature => \&literature,
},
WRAPPER => 'wrapper.tt',
);
my $vars = {};
print $q->header( -charset => 'utf-8' );
my $default_page = 'start';
my %valid_pages = map { basename($_, '.tt') => 1 } glob "$FindBin::Bin/templates/*.tt";
my $requested_page = $q->param('page') || '';
my $page = exists $valid_pages{ $requested_page } ? $requested_page : $default_page;
my $template = "$page.tt";
$vars->{page} = $page;
my $base = $q->url( -base => 1 );
if ( $base =~ /klaus\.de/ ) {
$vars->{base} = $q->url( -base => 1 );
}
else {
if ( $q->url =~ /tmay/ ) { # spielwiese
$vars->{base} = $q->url( -base => 1 ) . '/tmay/',
}
else {
$vars->{base} = $q->url( -base => 1 ) . '/cb/',
}
}
$tt->process( $template, $vars ) || carp $tt->error();
sub literature {
my $list = shift;
my @items = split /\n\n/, $list;
my @res;
foreach my $item (@items) {
if ( $ENV{SERVER_SOFTWARE} =~ /Apache.1/ ) {
utf8::decode($item);
}
my ($title, $more) = split /\n/, $item, 2;
$title = HTML::Element->new('span', class => 'booktitle' )->push_content( $title );
push @res, HTML::Element->new('li')->push_content( $title, ['br'], $more );
}
return HTML::Element->new('ol', class => 'literature')->push_content(@res)->as_XML;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl use warnings; use strict; use CGI; my $redirect_url = "http://example.org/"; my $cgi = CGI->new(); print $cgi->redirect( -uri => $redirect_url, -nph => 1, -status => '301 Moved Permanently', );
Quoteund möchte die Datei so um schreiben, dass beim Aufrufen automatisch auf eine andere Adresse weitergeleitet wird.
2019-02-11T23:25:15 Linuxer
Beispiel, ungetestet:
Code (perl): (dl )1 2 3 4 5 6 7 8 9 10 11 12 13 14 15#!/usr/bin/perl use warnings; use strict; use CGI; my $redirect_url = "http://example.org/"; my $cgi = CGI->new(); print $cgi->redirect( -uri => $redirect_url, -nph => 1, -status => '301 Moved Permanently', );
2019-02-12T08:59:54 rosti
Warum so umständlich? Eine Weiterleitung kannst Du direkt im Webserver konfigurieren (.htaccess) da muß nicht ein extra CGI-Prozess gestartet werden.
Und wenn es den Directory Index betrifft: Der braucht überhaupt keine Weiterleitung.
MfG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<VirtualHost *>
ServerName klausTest.de
DocumentRoot /var/www/cb
</VirtualHost>
<VirtualHost *>
ServerName www.klausTest.de
DocumentRoot /var/www/cb
</VirtualHost>
# Klaus (cb)
Alias /cb /var/www/cb
<Directory var/www/cb>
DirectoryIndex index.pl
AllowOverride All
AddHandler cgi-script .pl
Options All +Indexes +ExecCGI FollowSymLinks
RewriteEngine On
RewriteRule (.*).html$ /cb/index.pl?page=$1
</Directory>
# Tjoss May - Spielwiese fuer cb
Alias /tmay /home/tmay/kt_html
<Directory /home/tmay/kt_html>
DirectoryIndex index.pl
AllowOverride All
AddHandler cgi-script .pl
Options All +Indexes +ExecCGI FollowSymLinks
RewriteEngine On
RewriteRule (.*).html$ /tmay/index.pl?page=$1
</Directory>
DirectoryIndex index.html
AllowOverride All