Gallery2:Lighttpd URL Rewrite - Gallery Codex
Personal tools

Gallery2:Lighttpd URL Rewrite

From Gallery Codex

Introduction

The URL Rewrite module does not directly support lighttpd, but can be made to work by manually putting rewrite rules in place.

Instructions

  1. Get a working gallery2 installation
  2. In the Plugins section of the Site Admin web interface, configure the URL Rewrite module so that it uses Apache mod_rewrite; you might need to force the bypass of the tests, and tell it that it works
  3. Create the (unnecesary) .htaccess file and give it read-write permissions. The commands should look something like this:
touch /srv/www/localhost/gallery2/.htaccess
chmod 666 /srv/www/localhost/gallery2/.htaccess
  1. Complete activation of URL Rewrite module; if you want, you can remove all the contents of the .htaccess file created by gallery2
  2. Activate the Permalinks module if desired
  3. Edit as root your Lighty's configuration file, which may be at /etc/lighttpd/lighttpd.conf and uncomment (remove the #) of the line in which you can read mod_rewrite. If you cannot find this line, just add "mod_rewrite",' to the server.modules section. For example, mine looks like this:
server.modules              = (
                               "mod_rewrite",
                               "mod_access",
                               "mod_fastcgi",
                               "mod_ssi",
                               "mod_usertrack",
                               "mod_accesslog" )

Your Lighty will load that module. Now you have to add the url.rewrite rules to your configuration file. Lighty will parse the requested url and go transparently to the destination defined after the '=>'. Add these lines to your /etc/lighttpd/lighttpd.conf file:

url.rewrite = (
 "^/(.*)/Rewrite.txt$" => "/$1/Works.txt",
 "^/gallery2/v/(\?.+|\ .)?$" => "/gallery2/main.php?g2_view=core.ShowItem",
 "^/gallery2/admin[/?]*(.*)$" => "/gallery2/main.php?g2_view=core.SiteAdmin&$1",
 "^/gallery2/d/([0-9]+)-([0-9]+)/([^\/]+)(\?|\ )?(.*)$" =>
 "/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&$3",
 "^/gallery2/v/([^?]+)/slideshow.html" =>
 "/gallery2/main.php?g2_view=slideshow.Slideshow&g2_path=$1",
 "^/gallery2/v/([^?]+)(\?|\ )?(.*)$" =>
 "/gallery2/main.php?g2_view=core.ShowItem&g2_path=$1&$3",
 "^/gallery2/c/add/([0-9]+).html" =>
 "/gallery2/main.php?g2_view=comment.AddComment&g2_itemId=$1",
 "^/gallery2/c/view/([0-9]+).html" =>
 "/gallery2/main.php?g2_view=comment.ShowAllComments&g2_itemId=$1",
 "^/gallery2/f/(.+)" =>
 "/gallery2/main.php?g2_controller=permalinks.Redirect&g2_filename=$1",
 "^/gallery2/key/([^?]+)(\?|\ )?(.*)$" =>
 "/gallery2/main.php?g2_view=keyalbum.KeywordAlbum&g2_keyword=$1&$3",
 "^/gallery2/contact" =>
 "/gallery2/main.php?g2_view=contactowner.Contact",
 "^/gallery2/srss/([0-9]+)$" =>
 "/gallery2/main.php?g2_view=rss.SimpleRender&g2_itemId=$1",
 "^/gallery2/v/([^?]+)/slideshowapplet.html" =>
 "/gallery2/main.php?g2_view=slideshowapplet.SlideshowApplet&g2_path=$1",
 "^/gallery2/updates(\?.+|\ .)?$" =>
 "/gallery2/main.php?g2_view=dynamicalbum.UpdatesAlbum",
 "^/gallery2/popular(\?.+|\ .)?$" =>
 "/gallery2/main.php?g2_view=dynamicalbum.PopularAlbum",
 "^/gallery2/random(\?.+|\ .)?$" =>
 "/gallery2/main.php?g2_view=dynamicalbum.RandomAlbum"
 )

(Note: while the dynamic album rewrite rules--the last three rules above--work for the first page, it seems for some reason using the Next, Last, or page links always show page 1. If you know how to correct this, please login and edit this page.)

If needed, change gallery2 to your gallery2 path. The above rules are for the default patterns in the URL Rewrite module (the /v/, /d/, etc parts above). Any changes to these in URL Rewrite Site Admin will require matching changes to these rules.

Stop Lighty, and start it again from a commandline to see if you have made any typo. If it gives no error, it should be working.

Links

  • Thanks to Matthew Kincaid for the initial conversion of Apache rewrite rules to lighttpd.