Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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