tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / general / redirect
1 # Blosxom Plugin: redirect
2 # Author: Fletcher T. Penney (http://fletcher.freeshell.org)
3 # Version: 0.1
4
5 package redirect;
6  
7
8 # --- Configurable variables ---
9
10 # Where is the redirect file?
11 $redirect_file = "$blosxom::plugin_state_dir/redirect";
12
13 # ------------------------------
14
15 $path = $blosxom::path_info;
16
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;
34 }
35
36
37 sub last {
38         # We only end up here if we are redirecting this url
39
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;
46 }
47
48 1;
49
50
51 __END__
52
53 =head1 NAME
54
55 Blosxom Plug-in: redirect
56
57 =head1 SYNOPSIS
58
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.
60
61 The difficulty with this is that the url's don't really get fixed.
62
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.
64
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
67
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/=>
70
71 Basically it strips out the weblog directory, creating a URL that is now valid.
72
73
74 =head1 VERSION
75
76 Version 0.1
77
78 =head2 VERSION HISTORY
79
80 0.1     - initial public release
81
82 =head1 BUGS
83
84 None known; please send bug reports and feedback to the Blosxom
85 development mailing list <blosxom-devel@lists.sourceforge.net>.
86
87 =head1 AUTHOR
88
89 Fletcher T. Penney, http://fletcher.freeshell.org
90
91 This plugin is now maintained by the Blosxom Sourceforge Team,
92 <blosxom-devel@lists.sourceforge.net>.
93
94 =head1 LICENSE
95
96 Blosxom Redirect Plug-in
97 Copyright 2003, by Fletcher T. Penney
98
99 Permission is hereby granted, free of charge, to any person obtaining a
100 copy of this software and associated documentation files (the "Software"),
101 to deal in the Software without restriction, including without limitation
102 the rights to use, copy, modify, merge, publish, distribute, sublicense,
103 and/or sell copies of the Software, and to permit persons to whom the
104 Software is furnished to do so, subject to the following conditions:
105
106 The above copyright notice and this permission notice shall be included
107 in all copies or substantial portions of the Software.
108
109 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
112 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
113 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
114 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
115 OTHER DEALINGS IN THE SOFTWARE.