Gallery2:Lighttpd URL Rewrite - Gallery Codex
Personal tools

Gallery2:Lighttpd URL Rewrite

From Gallery Codex


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


  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_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/v/([^?]+)/slideshow.html" =>
 "^/gallery2/v/([^?]+)(\?|\ )?(.*)$" =>
 "^/gallery2/c/add/([0-9]+).html" =>
 "^/gallery2/c/view/([0-9]+).html" =>
 "^/gallery2/f/(.+)" =>
 "^/gallery2/key/([^?]+)(\?|\ )?(.*)$" =>
 "^/gallery2/contact" =>
 "^/gallery2/srss/([0-9]+)$" =>
 "^/gallery2/v/([^?]+)/slideshowapplet.html" =>
 "^/gallery2/updates(\?.+|\ .)?$" =>
 "^/gallery2/popular(\?.+|\ .)?$" =>
 "^/gallery2/random(\?.+|\ .)?$" =>

(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.


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