New Drupal/Gallery2.2 plugin configuration challenges

I like to my rewrite rules performed in the central Apache config (well, individual vhost files) so it can be revision controlled and centrally managed. The recent upgrade to the Gallery 5.x-2.0 module broke the rewriting rules I was using. Below are my new rewrite rules for a site-wide Gallery/Drupal install, but first the main snipped and differences of what was changed. For reference, my gallery install is at /photo.

The recommended URL rewrite rules would look like this:

RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /photo/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]

RewriteCond %{THE_REQUEST} /gallery/([\^?]+)(\?.|\ .)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_path=%1 [QSA,L]

I had to modify/remove the emphasized parts; I needed to change %{THE_REQUEST} to %{REQUEST_URI} because the path /gallery is also in drupal's admin paths. I wanted to anchor the /gallery gallery path, but can't do that with %{REQUEST_URI}. Also, because I removed %{REQUEST_URI}, I needed to remove the (\?.|\ .) match from the end since there would no longer be those characters after the URL.

My modified version would like like this (emphasis added to show changes):

RewriteCond %{REQUEST_URI} ^/gallery/([0-9]+)-([0-9]+)/([^/?]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /photo/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/([\^?]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_path=%1 [QSA,L]

This wasn't good enough for me, though, as I wanted the clean URLs I had for most gallery paths in gallery 2.1. So my final Gallery2.2/Drupal config looks like the following:

# drupal/gallery integration

RewriteCond %{REQUEST_URI} \^/gallery/popular

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=dynamicalbum.PopularAlbum [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/updates

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=dynamicalbum.UpdatesAlbum [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/random

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=dynamicalbum.RandomAlbum [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/d/([0-9]+)-([0-9]+)/([\^/?]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /photo/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/v/([\^?]+)/slideshow\.html

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=slideshow.Slideshow&g2_path=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/c/view/([0-9]+)\.html

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=comment.ShowAllComments&g2_itemId=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/c/add/([0-9]+)\.html

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=comment.AddComment&g2_itemId=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/v/([\^?]+)\.davmount

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=webdav.DownloadDavMount&g2_path=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/rating/([\^?/]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=rating.RatingAlbum&g2_limit=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/rss/([\^\/\?]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=rss.Render&g2_name=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/srss/([0-9]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=rss.SimpleRender&g2_itemId=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/key/([\^?/]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_view=keyalbum.KeywordAlbum&g2_keyword=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/w(/[\^?]*)?

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_controller=webdav.WebDav&g2_path=%1 [QSA,L]

RewriteCond %{REQUEST_URI} \^/gallery/v/([\^?]+)

RewriteCond %{REQUEST_URI} !/index\.php\$

RewriteRule . /index.php?q=gallery&g2_path=%1 [QSA,L]

# drupal configuration

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !\^/(photo|album|download)(/.*)?

RewriteRule \^(.*)\$ /index.php?q=\$1 [L,QSA]

links

social