Here’s how to get your old Gallery 1 URLs to redirect through the Gallery 2 URL mapper, through the Gallery 3 URL mapper into current Gallery 3 URLs
Redirect Sequence
This will result in this sequence of redirects :
- http://g1.example.com/albums/example-albumname/example-image.jpg
- Original request for a Gallery 1 image
- http://g2.example.com/gallery/main.php?g2_controller=migrate.Redirect&g2_path=/albums/example-albumname/example-image.jpg
- Redirect to the Gallery 2 Gallery 2 “Migrate” module, passing it the full path to the Gallery 1 image
- http://g2.example.com/gallery/main.php?g2_view=core.DownloadItem&g2_itemId=12345
- Redirect to the Gallery 2 URL that would serve that image if we were still using Gallery 2
- http://g3.example.com/g2/map?path=main.php&g2_view=core.DownloadItem&g2_itemId=12345
- Redirect to the Gallery 3 “map” function in the Gallery 3 “g2_import module”
- http://g3.example.com/var/albums/example-albumname/example-image.jpg?m=1355751254
- The final Gallery 3 URL that will serve up the image
Apache httpd config
Some assumptions :
- I’m using an unrelated rewrite for Gallery 3 that removes the “/gallery3/index.php/” portion of the URL. If you don’t use this some of these rewrites will have the /gallery3/index.php/ in them
<VirtualHost *:80>
DocumentRoot /path/to/g2site
ServerName g2.example.com
RewriteEngine On
# This rewrites requests from people just typing in your g2 site root URL to your g3 site
# http://g2.example.com/ -> http://g3.example.com/
RewriteRule ^/$ http://g3.example.com/ [L,R=301]
<Directory /path/to/g1site/albums>
# This code originates from the Gallery 2 "Migrate" plugin/module
# http://codex.galleryproject.org/Gallery2:Modules:migrate
# The only changes made here are to add a "L" directive to the RewriteRule
# To force mod_rewrite to stop processing if it gets a match
# and to add a "R=301" directive to indicate this is a permanent redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !gallery_remote2.php
RewriteRule (.*)$ /gallery/main.php?g2_controller=migrate.Redirect&g2_path=$1 [QSA,L,R=301]
</IfModule>
</Directory>
<Directory /path/to/g2site/gallery>
# This code takes incoming Gallery 2 URLs and passes them to the Gallery 3 URL mapper
# (convert g2 urls to g3 urls). Here we ignore requests that contain
# "g2_controller=migrate.Redirect" because these need to be processed by the
# Gallery 2 URL mapper (convert g1 urls to g2 urls)
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /gallery/
RewriteCond %{QUERY_STRING} !^g2_controller=migrate\.Redirect
RewriteRule ^(.*)$ http://g3.example.com/g2/map?path=$1 [QSA,L,R=301]
</IfModule>
</Directory>
</VirtualHost>
Original Apache httpd config snippets
Original unmodified Gallery 2 Migrate Module apache config This config was put in an .htaccess file in your Gallery 1 “albums” directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !gallery_remote2.php
RewriteRule (.*)$ /gallery/main.php?g2_controller=migrate.Redirect&g2_path=$1 [QSA]
</IfModule>
Original unmodified Gallery 3 g2_import apache config This config was put in gallery2/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /gallery/
RewriteRule ^(.*)$ /g2/map?path=$1 [QSA,L,R=301]
</IfModule>
Prior art
Here is a thread with people trying to create this but without luck : http://galleryproject.org/node/103597