# Blosxom Plugin: noslashredir # Author(s): Frank Hecker # Version: 0.1 # Documentation: See the bottom of this file or type: perldoc noslashredir package noslashredir; use strict; use CGI qw/:standard :netscape/; # --- Configurable variables ----- my $debug = 0; # set to 1 to print debug messages # -------------------------------- use vars qw!$redirecting!; # 1 if we are redirecting, 0 if not sub start { $redirecting = 0; 1; } sub filter { my ($pkg, $files_ref) = @_; warn "noslashredir: \$path_info: '" . $blosxom::path_info . "'\n" if $debug > 0; warn "noslashredir: path_info(): '" . path_info() . "'\n" if $debug > 0; # If the requested URI does not include a file extension (thus, it # represents the blog root, a category, or a date-based archive page) # and the requested URI does not end in a slash ('/') then add a slash # to the URI and force a redirect. # # Note 1: We use $blosxom::path_info to check for the presence of a # file extension because it may not have been present in the original # URI but rather might have been added by the extensionless plugin. # # Note 2: We use path_info() to check for the presence of a trailing # slash because the blosxom.cgi code strips trailing slashes from # $blosxom::path_info and does not include the date components. if ($blosxom::path_info !~ m!\.! && path_info() !~ m!/$!) { my $uri = "$blosxom::url" . path_info() . "/"; $uri .= "?" . $ENV{QUERY_STRING} if $ENV{QUERY_STRING}; warn "noslashredir: redirecting to '$uri'\n" if $debug > 0; my $message = qq!Trailing slash omitted, redirecting to $uri.\n!; $blosxom::output = $message; print "Status: 301\n"; print "Location: $uri\n"; $redirecting = 1; } 1; } sub skip { return $redirecting; # skip story generation if redirecting } 1; __END__ =head1 NAME Blosxom plugin: noslashredir =head1 SYNOPSIS Have Blosxom force a redirect if a non-entry URI does not have a trailing slash. =head1 VERSION 0.1 =head1 AUTHOR Frank Hecker , http://www.hecker.org/ This plugin is now maintained by the Blosxom Sourceforge Team, . =head1 DESCRIPTION This plugin checks to see if the requested URI corresponds to a category or date-based archive page and forces a redirect if the URI omits a trailing slash; it assumes that you are using URI rewriting rules to hide use of "/cgi-bin/blosxom.cgi". (Otherwise using the plugin wouldn't make much sense.) For example, if you request the URI http://www.example.com/blog/foo where "foo" is a category, this plugin will force a redirect to the URI http://www.example.com/blog/foo/ This plugin was inspired by the redirect plugin by Fletcher T. Penny http://www.blosxom.com/plugins/general/redirect.htm and adapts a bit of its code. =head1 INSTALLATION AND CONFIGURATION Copy this plugin into your Blosxom plugin directory. You do not normally need to rename the plugin; however see the discussion below. You can change the value of the variable C<$debug> to 1 if you need to debug the plugin's operation; the plugin will print to the web server's error log the original path component of the URI and the new URI if redirection is to be done. This plugin supplies only a filter and skip subroutine and can normally coexist with other plugins with filter subroutines. However this plugin needs to be run after the extensionless plugin, since it needs the file extension to distinguish between individual entry pages and other pages. Finally, note that this plugin is sensitive to the exact URI rewriting rules you might have configured (e.g., in an Apache configuration file or in a .htaccess file). In particular, when rewriting URIs to add the name of the Blosxom CGI script (e.g., "/cgi-bin/blosxom.cgi") you need to ensure that such rules preserve any trailing slash on the end of the URI and pass it on to Blosxom. =head1 SEE ALSO Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/ Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html =head1 BUGS At present the plugin forces a redirect for a date-based URI that specifies a particular day, for example http://www.example.com/blog/2004/10/25 This is arguably incorrect, since (unlike URIs specifying only the year or only the year and month) such a URI is not analogous to a directory. Please send bug reports and feedback to the Blosxom development mailing list . =head1 LICENSE noslashredir Blosxom plugin Copyright 2004 Frank Hecker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.