EPrints Technical Mailing List Archive

Message: #06255


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

Re: [EP-tech] eprints links are including filesystem paths


> You are awesome

:o) Thank you - glad I could help!

 

In my initial response I mentioned "deal with requests for the URLs with …/usr/share/eprints3/data/… in them by redirecting them (I can show you how)".

 

This is useful if anyone has bookmarked records with the old URL format, or anything that has harvested your repository before you fixed stuff.

 

I've created the file as a Gist - as the email list sometimes changes some characters:

https://gist.github.com/jesusbagpuss/feae833641fcaa056a45771e3c10f922

 

The code is copied below - but it's probably safer to use the link above.

It uses the 'EP_TRIGGER_URL_REWRITE' - there's an example of this in <eprints_root>/archives/<archiveid>cfg/cfg.d/rewrite_url_demo.pl, or if this file doesn't exist, look in <eprints_root>/lib/defaultcfg/cfg.d/rewrite_url_demo.pl

 

To implement the URL rewrites, create a file:

<eprints_root>/archives/<archiveid>/cfg/cfg.d/z_rewrite_old_urls.pl

And save the code into it.

 

Test the configuration:

<eprints_root>/bin/epadmin test <archiveid>

This should not return any errors.

Restart Apache.

Test a url that contains the old 'usr/share/eprints3/data' path e.g.

http://eprints.iliauni.edu.ge/usr/share/eprints3/data/cgi/search/advanced

or

http://eprints.iliauni.edu.ge/usr/share/eprints3/data/cgi/oai2?verb=Identify

and you should get redirected (with a 301 'Permanently moved') to the right place!

 

If there are any problems, remove the z_rewrite_old_urls.pl file and restart Apache.

 

Cheers,

John

 

#######################################################################################

# This is an example of how to use the URL Rewrite trigger.

# In this case, specifically an archive that was initially configured with

# a base path (url) of '/usr/share/eprints3/data' rather than '' (no default path).

#

# This file should be saved to:

# <eprints_root>/archives/<archiveid>/cfg/cfg.d/z_rewrite_old_urls.pl

#

# This trigger will rewrite any requests that match:

# <host>/usr/share/eprints3/data/<something>

# to:

# <host>/<something>

# with a permanent redirect (301 response).

#

# For info, the hash keys in %o (passed into the Trigger) are:

#                request # Apache2::RequestRec

#                   lang # e.g. 'en'

#                   args # "" or "?foo=bar"

#                urlpath # "" or "/subdir"

#                cgipath # /cgi or /subdir/cgi

#                    uri # /foo/bar - incoming request

#                 secure # boolean - true if request was https

#            return_code # set this to trigger an http response of that code

# For more info see: https://wiki.eprints.org/w/Anatomy_of_a_request#EP_TRIGGER_URL_REWRITE

# or EPrints::Apache::Rewrite

 

use strict;

use EPrints::Const;

 

$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {

    my( %o ) = @_;

 

    my $old_path = "usr/share/eprints3/data";   

 

    if( my ($path) = $o{uri} =~ /^\/$old_path\/(.*?)$/ )

    {

        EPrints::Apache::AnApache::send_status_line( $o{request}, 301, "Moved Permanently" );

        EPrints::Apache::AnApache::header_out( $o{request}, "Location", "/$path".$o{args}  );

        EPrints::Apache::AnApache::send_http_header( $o{request} );

 

        ${$o{return_code}} = EPrints::Const::DONE;

        return EP_TRIGGER_DONE;

 

    }

 

    # if we're not doing anything, don't return anything, the request will continue as normal.

});

#######################################################################################

 

 

 

From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of David Machakhelidze
Sent: 03 February 2017 19:48
To: eprints-tech@ecs.soton.ac.uk
Subject: Re: [EP-tech] eprints links are including filesystem paths

 

sorry
I shoult regenerate_static, abstract, views and then restart apache 2 
everything works great !

Thank you John, You are awesome

 

On Fri, Feb 3, 2017 at 11:44 PM David Machakhelidze <david.machakhelidze@iliauni.edu.ge> wrote:

I have changed config file
regenerated apache2 config
restarted apache2
But when i try to reach documents I get 404 error

for example

http://eprints.iliauni.edu.ge/usr/share/eprints3/data/6222/1/Ketevan%20kupatadze_Istanbul.ppt

 

On Fri, Feb 3, 2017 at 7:23 PM John Salter <J.Salter@leeds.ac.uk> wrote:

NOTE: **I haven't tried the process below (be careful!)**

You might want to test the sequences below before trying them on the live server, or at least take a copy of all the config files (<eprints_root>/archives/<archiveid>/cfg) as a backup.

 

When the archive was created, the script

<eprints_root>/bin/epadmin create

would have been run. This configures parts of the repository, one of which is the URL path the repository lives at.

The question asked during this process is:

"Please enter the path part of the repository's base URL. This should probably be '/'."

 

I think this was answered with '/usr/share/eprints3/data/' - the location on the disk, rather than the URL you wanted.

 

The value is saved into the archive config, in:

<eprints_root>/archives/<archiveid>/cfg/cfg.d/10_core.pl

 

The line:

$c->{http_root} = '/usr/share/eprints3/data/';

Could be changed to:

$c->{http_root} = undef;

 

 

After doing this you will need to update the apache conf:

<eprints_root>/bin/generate_apacheconf

 

You will need to re-start Apache to make the change live.

 

You will probably also want to:

Generate the static pages:

<eprints_root>/bin/generate_static <archiveid>

And possibly generate the abstract pages:

<eprints_root>/bin/generate_static <archiveid>

 

 

If your repository has been running for a while like this, you might want to deal with requests for the URLs with …/usr/share/eprints3/data/… in them by redirecting them (I can show you how).

 

Cheers,

John

 

 

 

From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of David Machakhelidze
Sent: 03 February 2017 14:44
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] eprints links are including filesystem paths

 

For examples

 

This is what it likes when I click on the HOME ink

http://eprints.iliauni.edu.ge/usr/share/eprints3/data/

 

And this is for search

 

 

and so on an so on, my links include /usr/share/eprints3/data/.........

I see other eprints sites does not have such problem, how to fix that?

*** 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/
*** EPrints developers Forum: http://forum.eprints.org/

*** 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/
*** EPrints developers Forum: http://forum.eprints.org/