Add Fletcher Penney plugins to general.
[blosxom-plugins.git] / general / redirect
blobb97ac88b45b7095eb274fd52a74470a985f7e4b3
1 # Blosxom Plugin: redirect
2 # Author: Fletcher T. Penney (http://fletcher.freeshell.org)
3 # Version: 0.1
5 package redirect;
6  
8 # --- Configurable variables ---
10 # Where is the redirect file?
11 $redirect_file = "$blosxom::plugin_state_dir/redirect";
13 # ------------------------------
15 $path = $blosxom::path_info;
17 sub start {     
18 warn "Flavour check $blosxom::flavour\n";
19         if (open (REDIRECT, "< $redirect_file")) {
20                 while ( $line = <REDIRECT> ) {  
21                         if ($line =~ /(.*)=>(.*)/) {
22                                 $old = $1;
23                                 $new = $2;
24                                 if ( $path =~ s/^$old/$new/ ) {
25                                         return 1;
26                                 }
27                         }
28                 }
29                 
30                 close REDIRECT;
31         }
32         
33         return 0;
37 sub last {
38         # We only end up here if we are redirecting this url
40         $message = qq!This page has been moved.  The new URL is <a href="$blosxom::url/$path">$blosxom::url/$path</a>.\n!;
41         
42         $blosxom::output = $message;
43         print "Status: 301\n";
44         print "Location: $blosxom::url/$path\n";
45         1;
51 __END__
53 =head1 NAME
55 Blosxom Plug-in: redirect
57 =head1 SYNOPSIS
59 One problem with having a weblog is that you become somewhat committed to your URL structure.  If you decide to rearrange your site, you run the risk of breaking external links.  The autocorrect plugin helps, attempting to find a story that might have moved.
61 The difficulty with this is that the url's don't really get fixed.
63 I recently moved my site out  of the "/weblog" directory by improving my .htaccess file.  I like the url's better, but I have lots of links out there that still point to the "/weblog" hierarchy.  I came up with some ways of pointing this out to human viewers, but robots still travel the old hierarchy, and it's a pain for people to figure out where to go.
65 This plugin allows you to set up a redirect file that consists of lines like the following:
66 path/to/some/article=>new/path/to/article
68 If someone tries to go to a non-existent directory, you can re-route them automatically to the new location, and the url is updated in their browser.  For instance, my redirect file looks like this:
69 weblog/=>
71 Basically it strips out the weblog directory, creating a URL that is now valid.
74 =head1 VERSION
76 Version 0.1
78 =head2 VERSION HISTORY
80 0.1     - initial public release
82 =head1 AUTHOR
84 Fletcher T. Penney, http://fletcher.freeshell.org
86 =head1 LICENSE
88 Blosxom Redirect Plug-in
89 Copyright 2003, by Fletcher T. Penney
91 Permission is hereby granted, free of charge, to any person obtaining a
92 copy of this software and associated documentation files (the "Software"),
93 to deal in the Software without restriction, including without limitation
94 the rights to use, copy, modify, merge, publish, distribute, sublicense,
95 and/or sell copies of the Software, and to permit persons to whom the
96 Software is furnished to do so, subject to the following conditions:
98 The above copyright notice and this permission notice shall be included
99 in all copies or substantial portions of the Software.
101 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
104 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
105 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
106 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
107 OTHER DEALINGS IN THE SOFTWARE.