Integration:Drupal:Installation:URL Rewrite - Gallery Codex
Personal tools

Integration:Drupal:Installation:URL Rewrite

From Gallery Codex

The Clean URL / Rewrite modules leverage web server's, like Apache, ability to rewrite Gallery URL requests like http://www.site1.com/?q=gallery&g2_itemId=24 to a more human-readable formats like http://www.site1.com/gallery/album/image.jpg.html.

In most single site installations, configuring clean URL support in the Gallery Module is straightforward. Atypical server and site configurations can, however, present challenges when enabling clean URLs.

Single site configuration

  1. Configure the Rewrite Module in your standalone Gallery
  2. Enable clean URLs in Drupal
  3. Make Drupal's htaccess file temporarily writeable
    chmod 666 /path/to/drupal/.htaccess
  4. In Drupal's Administer area, select Site Configuration>Gallery Settings
  5. Select the Install tab
  6. Expand Step 4: Clean URLs / URL Rewrite settings
  7. Confirm or correct your Drupal file path and URL
  8. Click the Test htaccess button

You should see an 'OK' status upon success.

Multi site configuration

Configuration of clean URLs in multisite environments requires a bit more work on your part. Typically, the best approach involves configuring clean URLs for a single site, backing up your Drupal htacces, then replicating the rewrite rules for each subsequent site.

If each Gallery site's Mod Rewrite rules are the same, copy and paste the first rule set for each additional site and edit paths accordingly.

A Gallery module rewrite rules block appears above Drupal's rewrite rules. The following is an example block:

 # BEGIN Url Rewrite section
 # (Automatically generated.  Do not edit this section)
 <IfModule mod_rewrite.c>
   Options +FollowSymlinks
   RewriteEngine On
   
   RewriteBase /
   
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d [OR]
   RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   -   [L]
   
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/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]
 </IfModule>

The part you'll need to duplicate to add another site is:

   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/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]

Copy this block, paste it below the original, and edit the url in the DownloadItem line. The final gallery.module rewrite block would like like:

 # BEGIN Url Rewrite section
 # (Automatically generated.  Do not edit this section)
 <IfModule mod_rewrite.c>
   Options +FollowSymlinks
   RewriteEngine On
   
   RewriteBase /
   
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d [OR]
   RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   -   [L]
   
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site1.com/gallery2/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]
   RewriteCond %{THE_REQUEST} /gallery/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
   RewriteCond %{REQUEST_URI} !/index\.php$
   RewriteRule .   /sites/site2.com/gallery2/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]
 </IfModule>

Troubleshooting

Support for this feature relies on the availability of Apache's mod_rewrite module. It is impossible to enable clean URLs without it. Check with your web hosting provider if you're unsure whether mod_rewrite is enabled.

Installing Gallery 2 in a folder named 'gallery' within your Drupal directory will create rewrite conflicts and make enabling clean URLs impossible. Disable the URL Rewrite moduel in Gallery, rename the Gallery 2 folder to anything but 'gallery', re-enalbe Gallery's Rewrite Module, and try again.

If you experience an error like this when navigating to Drupals gallery settings pages;

Error (ERROR_MISSING_OBJECT) : Parent 7 path install

Try changing this line;

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

To;

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