Gallery2 - moving to new URL

Long ago I installed Gallery2. It was initially just a test installation to see if it worked, as it should. Being a test install it was just placed at /g2/ on this server. Time passed. It just worked and before long, there were a large number of photos (with metadata) in the gallery. So how do you move it to a slightly more suitable location without breaking too many things? I tried it a few times before, but with very little success. Now it’s done, I can only wonder why it seemed difficult to do it in the past – it’s really quite simple. Here’s how to do it:

  • Rename the folder (”mv g2 gallery” in my case)
  • Edit the .htaccess file in the gallery directory, if you use clean URLs (I replaced /g2/ with /gallery/ everywhere – remember, only where slashes are pressent before and after g2).
    The gallery should now be working at the new URL.
  • If you’re running with apache and have mod_rewrite available, rewrite the old URLs to new. I used this line in my apache config file:
    RewriteRule ^\/g2\/(.*) \/gallery\/$1 [L,R=301]

The 301 code, in the rewrite should help Google and other search engines discover the move faster.