Skip to content

Creating a single ‘latest photos’ RSS feed in Gallery 3 with a friendly URL

G8th September 2011

C2 Comments

TApache, Gallery 3

Use mod_rewrite and a few modules to provide your Gallery 3 visitors with a single, SEO-friendly RSS feed showing links to just your latest photo uploads.

Gallery 3 is a PHP-based open-source photo album organiser for use in developing photo gallery websites.

Gallery 3 relies on a series of modules which add functionality to the core code. To generate an RSS feed, the RSS module needs to be installed. Whist this provides an RSS feed for every album in the gallery, it has some deficiencies:

  • The RSS feed URLs are long and ugly, being in the format http://www.mywebsite.com/rss/feed/gallery/album/(album number)/
  • There is no overall RSS feed that links to just the very latest uploads
  • RSS feed links are automatically placed into the sidebar on every page.

What I wanted to do was to create a single feed for the entire website that links to my latest uploads, regardless of which directory the new photos are placed in.

This procedure relies on the installation of a number of modules,  various code modifications and several procedures to work properly. The method is written for Gallery 3.0.2 which is the latest version at the time of writing. Your web server will need to be running Apache with mod_rewrite enabled.

Step 1:

Open your .htaccess file and add the following code.

RewriteCond %{THE_REQUEST} \?page=([0-9]+).*
RewriteRule (.*) $1page/%1/? [R=301,L]
RewriteRule (.*)/page/1 $1 [R=301,L]
RewriteRule ^(.*)page/([^/\.]+)/?$ $1?page=$2 [L]

 
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^index.php/(.*) $1 [QSA,R,L]
 

This will change the URL structure of your Gallery 3 installation so that SEO-friendly URLs are produced.

Using an FTP programme, transfer your modified .htaccess file to your website’s directory root.

Open the paginator.html.php file from the themes/(yourtheme)/views/ folder. Add the following code after the opening comments:


This part of our procedure was developed by Miles J. Carter and is explained in detail on his blog. I have made slight modifications to his code.

Step 2:

Go to your Gallery 3 website and check that the pagination is working correctly before proceeding further.

Step 3:

Install the LatestUpdates module. This will create a dynamic directory that contains the latest uploads. If you don’t want this directory to be visible to site visitors, you can remove it from the sidebar by logging into Gallery 3, going to the dashboard and selecting Admin > Appearance > Manage Sidebar.

To install LatestUpdates, download the zip file from the Gallery 3 modules website and extract the contents locally into your /modules/ directory. Upload the folder and contents to your web server under http://www.mywebsite.com/modules/ . To activate, log into Gallery 3 the go to the dashboard and click on the “Modules” menu item. Tick the “LatestUpdates” box then click the “Update” button at the bottom.

Step 4:

Remove the RSS feeds from the sidebar using the above method. The reason that I suggest that this link be removed is to facilitate the promotion of the single catch-all RSS feed. Ultimately, this step is optional.

Step 5:

Thanks to the LatestUpdates module, an RSS feed is now available for the ‘latest uploads’ dynamic album. By default, the RSS feed address is http://www.mywebsite.com/rss/feed/gallery/latest/. I want to shorten this URL to http://www.mywebsite.com/rss/

To do this, open the .htaccess file, and add the following line to the bottom of your RewriteRules.

RewriteRule ^(rss/)$ rss/feed/gallery/latest/$1 [NC] [L]

This code uses mod_rewrite to redirect the RSS feed URL from http://www.mywebsite.com/rss/feed/gallery/latest/ to http://www.mywebsite.com/rss/. If, for example, you want the RSS feed to be available at http://www.mywebsite.com/feed/ instead, the first part of the code can be changed accordingly. The choice is yours.

Using an FTP programme, transfer your modified .htaccess file to your website’s directory root.

Shown together (and in correct order), your modified .htaccess code should resemble the following:

RewriteCond %{THE_REQUEST} \?page=([0-9]+).*
RewriteRule (.*) $1page/%1/? [R=301,L]
RewriteRule (.*)/page/1 $1 [R=301,L]
RewriteRule ^(.*)page/([^/\.]+)/?$ $1?page=$2 [L]
RewriteRule ^(rss/)$ rss/feed/gallery/latest/$1 [NC] [L]

 
   Options +FollowSymLinks
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
   RewriteRule ^index.php/(.*) $1 [QSA,R,L]
 

Step 6:

To make access to the RSS feed easy, open the page.html.php file from the themes/(yourtheme)/views/ folder. Add the following code to the <head>:

This will provide a link within browsers to the new RSS feed.

If you want to add a link within your page, you can modify the applicable template files in your Gallery 3 theme. I won’t go into details about how to do that in this post.

Step 7:

Log out of Gallery 3, then direct your browser to http://www.mywebsite.com/rss/ to make sure that the RSS feed is working properly. The feed should display links to your latest photo uploads. When you update your Gallery 3 website, the links in the RSS feed will be updated.

   

Comments:

2 responses to “Creating a single ‘latest photos’ RSS feed in Gallery 3 with a friendly URL”

  • Written by Miles Carter on 9 May 2012:

    Hi Adam, nice usage of my code and thanks for the credit! Might have to give this a go myself.

    Just thought I should explain that the .htaccess should really be structured differently (though with many server setups it won’t matter) – I’ve split it with line breaks for clarity, something which was lacking in my original post with regard to ordering etc.

     
       Options +FollowSymLinks
       RewriteEngine On
       RewriteBase /
    
    
    RewriteCond %{THE_REQUEST} \?page=([0-9]+).*
    RewriteRule (.*) $1page/%1/? [R=301,L]
    RewriteRule (.*)/page/1 $1 [R=301,L]
    RewriteRule ^(.*)page/([^/\.]+)/?$ $1?page=$2 [L]
    RewriteRule ^(rss/)$ rss/feed/gallery/latest/$1 [NC] [L]
    
    
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
       RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
       RewriteRule ^index.php/(.*) $1 [QSA,R,L]
    
  • Written by Miles Carter on 9 May 2012:

    The parser stripped out the ifmodule directive but that should be the first and last lines

Have your say:

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.