Forum OpenACS Development: New package: Redirect

Collapse
Posted by Tilmann Singer on
Inspired by the recent endeavour to change a URL on the openacs.org site without breaking old links, I've written a small package called Redirect that could be used to facilitate this task. I pasted its documentation below which should make it more than clear what it does.

My question is, where should I commit it? Any objections against adding it to openacs-4 HEAD? Should it even be a core package?

From it's doc:

This is a simple package that sends a redirect to another location, depending on its parameter settings. It is intended for the situation when you moved parts of your site to another location in order to reorganise your site, but don't want old links such as users bookmarks, links from remote sites, external search engine hits etc. to break.

Usage

Mount it at the old location using the openacs site-map, and set its NewURL parameter to the new location. E.g. when you moved a tree of your site from '/some/old/path/' to '/newurl/' then mount an instance of redirect at '/some/old/path/', and set its NewURL parameter to '/newurl/'.

Parameters

NewURL

The URL to redirect to. E.g. /some/path/ or http://anotherserver.com/some/path/.

Relative paths like 'some/other/path/' are not possible.

PreservePathRemainings

Wether to preserve the remainings of the requested path, e.g. if set to true then the redirect /some/old/path/bla/bla goes to /some/new/path/bla/bla, otherwise it goes to /some/new/path/, regardless of what followed the request. In most cases makes sense to leave set to true.

This also includes query parameters, so that a request for '/some/old/path/bla?item_id=100' gets redirected to '/newurl/bla?item_id=100' when set to true.

PermanentRedirect

Indicate to the requesting browser that this is a permanent redirect. The browser might react by updating a bookmark to the new url for example. Leave set to true if unsure.

Note that this results in different http status codes. A permanent redirect is http status 301, a non-permanent is 302. See general http documentation for more info about the consequences.

Collapse
2: Re: New package: Redirect (response to 1)
Posted by Jade Rubick on
Nice!

I think that might be a good candidate for core inclusion, personally. I'm sure every one of us has dealt with this on their sites -- it's a very common issue.

Why include it in the core? It solves a very common problem that all of us face?

Collapse
3: Re: New package: Redirect (response to 2)
Posted by Randy O'Meara on
It definitely belongs in the core.
Collapse
4: Re: New package: Redirect (response to 1)
Posted by Michael Bluett on
How easy is it to add, say 10 redirects (see this thread)?
Collapse
5: Re: New package: Redirect (response to 4)
Posted by Tilmann Singer on
Depends - hierarchies of links will be inherited by default, e.g. if the 10 links are like this:
/old/one -> /new/one
/old/two -> /new/two
...
one action in the site-map is sufficient (mount it at /old/). Otherwise you would have to create 10 subfolders and mount the package 10 times. I wonder though if that is necessary in practice that often?

Anyway, here's the redirect package if you want to have a try: https://openacs.org/storage/file?file_id=118294

Collapse
6: Re: New package: Redirect (response to 1)
Posted by Jade Rubick on
Here's an idea for someone sometime in the future:

If we expanded the redirect package to have the option of creating mapping tables, then you could very easily migrate from, say bboards to forums.

You'd have a Redirect API that would keep track of the mapping tables, and whenever someone went to /bboard?message_id=1234, then would then be redirected to /forums?msg_id=2335

It would only be a days work or so to write, and it would be tremendously valuable for future porting efforts.

Collapse
7: Re: New package: Redirect (response to 6)
Posted by Randy O'Meara on
Jade, you can do that easily now with a very simple index.vuh tcl script.
Collapse
8: Re: New package: Redirect (response to 7)
Posted by Tilmann Singer on
Looking at the code that currently does the bboard -> forums mapping at openacs.org I'm not sure if it would make sense / be possible to generalise for any package:

http://cvs.openacs.org/cvs/openacs.org-dev/www/bboard/index.vuh?rev=1.4&content-type=text/x-cvsweb-markup

Collapse
9: Re: New package: Redirect (response to 1)
Posted by Jade Rubick on
Yes, it's very easy to do.

However, that's part of the point. It would be an easy addition to Redirect. I'm not suggesting that anyone take it on at this point, but it would be an easy addition.

The way it would work would be:

there would be a table that had old_id and new_id

Redirect would also store the source directory and target directory, like it does now.

The only addition would be that when the source directory (redirect controlled) is called, it would also regexp the old_id out, and then when redirecting to the new directory, would substitute in the new_id from the mapping table.

Let's say I port data from ticket-tracker-lite to bug-tracker. In my migration script, I would call the Redirect API for each insert, also creating a mapping entry.

I personally would use this a lot. Actually, I see so much value in it, that I would consider writing it, if others felt it would be of use.

Collapse
10: Re: New package: Redirect (response to 9)
Posted by Randy O'Meara on
Sorry Jade. I missed the fact that the object id was also mapped. An index.vuh script couldn't do what you suggest unless it had access to the map. Your idea does have great merit in that it would provide *data migration* capability.