sub earlyInitPlugin { my $CGI = TWiki::Func::getCgiQuery(); $CGI->url(-absolute => 1) =~ m~^/([^/.]+)(.|/)?(.*)~; my $web = $1; my $topic = $3; if (TWiki::Func::topicExists($web, $topic)) { # Found the topic, no problems return undef; } else { # We could have arrived here without a topic, so get the # default topic name from TWiki if (!$topic) { $topic = (TWiki::Func::normalizeWebTopicName("",""))[1]; } # Didn't find the topic, does it exist case-insensitively elsewhere? my $baseDirectory = "YOUR DIR HERE"; my @possibleWebs; my @possibleTopics; my $redirectWeb; my $redirectTopic; opendir(WEBS, $baseDirectory); @possibleWebs = readdir(WEBS); foreach my $possibleWeb (@possibleWebs) { if (lc($web) eq lc($possibleWeb)) { $redirectWeb = $possibleWeb; last; } } opendir(TOPICS, $baseDirectory . "/" . $redirectWeb); @possibleTopics = readdir(TOPICS); foreach my $possibleTopic (@possibleTopics) { $possibleTopic =~ s/\.txt$//; if (lc($topic) eq lc($possibleTopic)) { $redirectTopic = $possibleTopic; last; } } # We have a match on both elements, so let's redirect if ($redirectWeb && $redirectTopic) { TWiki::Func::redirectCgiQuery(undef, TWiki::Func::getScriptUrl($redirectWeb, $redirectTopic, "view"), 1); } } # Failed to find anything, but that just means TWiki should continue as # normal return undef; }