EPrints Technical Mailing List Archive

Message: #09202

< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

Re: [EP-tech] Adding 301 redir_permanent for some migrated items before 404 kicks in.

CAUTION: This e-mail originated outside the University of Southampton.

You could do it in apache using RewriteMap

        RewriteMap newid "txt:/etc/apache2/newid.txt"
        RewriteCond ${newid:$1|Unknown} !Unknown
        RewriteRule "^/([0-9]+)/?$" "newserverurl/${newid:$1|$1}" [R,L]

but this will not work because eprints handler kicks in before Rewrite.

if the id on the secondary are different , RewriteMap will help you in mapping old ids to new ones.

What I did, for a migration, was to use cfg/cfg.d/urls.pl to add all the migrated eprints to /rewrite_exceptions (which will returns from the perl handler back to apache) and then use the RewriteMap above. Other options like using EPrints URL Rewrite can be found in the mailing list thread "redirect some eprintid url to another site".

Il 15/02/23 02:13, Matthew Brady via Eprints-tech ha scritto:
CAUTION: This e-mail originated outside the University of Southampton.

Hi All,


Running 3.3.16.


Looking to migrate some records from our primary system to a secondary system, and redirect all the bots we’ve collected over the years, via redir_permanent (301), for the migrated items to the new location (rather than have the primary show a 404).


I have based my initial attempt which is working, on the logic in cfg/cfg.d/rewrite_url_demo.pl, but it fires for every uri hit the server sees,… valid records, css, etc…


Is there a way to allow the system to function as usual, and then if the uri request cannot be found, fire this particular redirect logic, and if it falls through that, then present the 404 as usual??

Primarily just to keep the trigger from firing until needed… since I don’t need the trigger to lookup potentially ~000’s of eprintid’s, for every uri request coming through…


Original logic,

# $c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {

#             my( %o ) = @_;


#             if( $o{uri} eq $o{urlpath}."/testpath01" )

#             {

#                             ${$o{return_code}} = EPrints::Apache::Rewrite::redir( $o{request}, https://totl.net/ );

#                             return EP_TRIGGER_DONE;

#             }

# } );


Updated to

# $c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {

#             my( %o ) = @_;

#             my $url = "">

#             if( $url =~ m#^/(\d+)/#  || $url =~ m#^/id/eprint/(\d+)/# )            # <-- This snippet taken from cgi/handle_404

#             {

#                             if( $1 eq "99999" )

#                             {

#                                             ${$o{return_code}} = EPrints::Apache::Rewrite:: redir_permanent ( $o{request}, http://not.the.real.link.net/ );

#                                             return EP_TRIGGER_DONE;

#                             }

#             }






This email (including any attached files) is confidential and is 
for the intended recipient(s) only. If you received this email by 
mistake, please, as a courtesy, tell the sender, then delete this 
The views and opinions are the originator's and do not necessarily 
reflect those of the University of Southern Queensland. Although 
all reasonable precautions were taken to ensure that this email 
contained no viruses at the time it was sent we accept no 
liability for any losses arising from its receipt.
The University of Southern Queensland is a registered provider 
of education with the Australian Government.
(CRICOS Institution Code QLD 00244B / NSW 02225M, TEQSA PRV12081)

*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/