Use mod_rewite for album moves?

cchiappa
cchiappa's picture

Joined: 2008-08-11
Posts: 101
Posted: Mon, 2010-03-08 16:16

I'd like to be able to move an album, say /Chris/OldAlbum to another location, for instance, /Chris/2009/OldAlbum. I'm trying to use mod_rewrite to do this but having not used it before I'm not making much progress. For G2's .htaccess, I tried adding a section before the auto-generated one that looked like this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /gallery2/
    RewriteCond %{REQUEST_URI} ^/gallery2/v/Chris/(OldAlbum.*)
    RewriteRule . v/Chris/2009/%1
</IfModule>

The rewritelog initially looks promising:
[perdir /usr/share/gallery2/] RewriteCond: input='/gallery2/v/Chris/OldAlbum/' pattern='^/gallery2/v/Chris/(OldAlbum.*)' => matched
...but then it seems to rewrite it to something that doesn't look right:
[perdir /usr/share/gallery2/] add path info postfix: /usr/share/gallery2/v/Chris/2009/OldAlbum/ -> /usr/share/gallery2/v/Chris/2009/OldAlbum//Chris/OldAlbum/
and G2 just displays an "item not found" error.
As a change, I tried changing the RewriteRule to

    RewriteRule .   /gallery2/main.php?g2_path=v/Chris/2009/%1   [QSA,L]

to try to jump right to the relevant target, but while it does seem to get rewritten:
[perdir /usr/share/gallery2/] rewrite 'v/Chris/OldAlbum/
' -> '/gallery2/main.php?g2_path=v/Chris/2009/OldAlbum/'
it still displays the "item not found" error.

Any hints for a mod_rewrite noob? I feel like this should be easy but at the same time feel like I'm swinging in the dark...I have the full rewrite logs but wanted to avoid spamming the forum.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2010-03-08 17:21

First, if you are, I probably wouldn't be mucking around in G2's URL Rewrite section. If you do that and you go to Site Admin > URL Rewrite and change anything, all of your changes will be removed.

I'm no rewrite expert. First thing I'd try is a basic redirect, placed in the .htaccess before G2's URL Rewrite section

A quick search brought up this little tutorial:
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
cchiappa
cchiappa's picture

Joined: 2008-08-11
Posts: 101
Posted: Mon, 2010-03-08 20:09

I ran into weird interactions between mod_alias and mod_rewrite (it appeared it was being redirected but then rewritten using the original URL or something) but the idea of a redirect rather than a rewrite led me to google and land on another page:
http://www.tedpavlic.com/post_apache_rewriting_examples.php
which got me to try a form that does seem to work:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /gallery2/
    RewriteCond %{REQUEST_URI} ^/gallery2/v/Chris/(OldAlbum.*)
    RewriteRule . v/Chris/2009/%1 [R=permanent,L]
</IfModule>

So this returns a redirect to the browser and stops processing immediately - on the next pass we are in a new request with the expected, current, URL so that appears to work well. Thanks, and maybe this will be useful to someone in the future