Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
Last active March 14, 2022 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusbagpuss/a5c574e1839612ef7e332d1d25edac42 to your computer and use it in GitHub Desktop.
Save jesusbagpuss/a5c574e1839612ef7e332d1d25edac42 to your computer and use it in GitHub Desktop.
EPrints redirect specific URLs
use EPrints::Const;
my %rewrite_map = (
123 => 'https://other.site/321',
456 => 'https://else.where/stuff-999',
);
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {
my( %o ) = @_;
# Might need to consider $o{urlpath} here e.g.
# if( $o{uri} =~ m!^/$o{urlpath}/(\d+)/! )
if( $o{uri} =~ m!^/(\d+)/! )
{
my $eprintid = $1; #captured above
if( defined $rewrite_map{$eprintid} )
{
EPrints::Apache::AnApache::send_status_line( $o{request}, 301, "Moved Permanently" );
EPrints::Apache::AnApache::header_out( $o{request}, "Location", $rewrite_map{$eprintid} );
EPrints::Apache::AnApache::send_http_header( $o{request} );
${$o{return_code}} = EPrints::Const::DONE;
return EP_TRIGGER_DONE;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment