URL rewriting: Lighttpd

From Smart Job Board help

Smart Job Board Help > URL rewriting: Lighttpd
Jump to: navigation, search

Lighttpd does not support .htaccess and rules for mod_rewrite for Apache server. But lighttpd provides an opportunity to specify url rewriting rules in its own format.

Config Template

url.rewrite-if-not-file = (
"^/{$rewrite_path}admin/.*\?(.*)$" => "/{$rewrite_path}admin/index.php?$1",
"^/{$rewrite_path}admin/.*$" => "/{$rewrite_path}admin/index.php",
"^/{$rewrite_path}.*\?(.*)$" => "/{$rewrite_path}index.php?$1",
"^/{$rewrite_path}.*$" => "/{$rewrite_path}index.php"
) 

There $rewrite_path – is a path where the software installed relative to www directory. If the software is installed in the root of the www directory, then {$rewrite_path} has empty value.


Configuring


For connecting config file you need to do the following steps:

Step 1. Create config file

Example 1 If the software installed in www root, then {$rewrite_path} should be changed to a null value and create a file:

/home/user/www/lighttpd.url.rewrite.conf with access rights 644:

url.rewrite-if-not-file = (
"^/admin/.*\?(.*)$" => "/admin/index.php?$1",
"^/admin/.*$" => "/admin/index.php",
"^/.*\?(.*)$" => "/index.php?$1",
"^/.*$" => "/index.php"
)


Example 2

If on a some hosting http://www.example.com the path to the www root directory is /home/user/www/, the software is installed to the /sjb subdirectory (/home/user/www/sjb), and has the following URL http://www.example.com/sjb, then {$rewrite_path} = sjb/.
Create a file: /home/user/www/sjb/lighttpd.url.rewrite.conf with access rights 644:

url.rewrite-if-not-file = (
 "^/sjb/admin/.*\?(.*)$" => "/sjb/admin/index.php?$1",
 "^/sjb/admin/.*$" => "/sjb/admin/index.php",
 "^/sjb/.*\?(.*)$" => "/sjb/index.php?$1",
 "^/sjb/.*$" => "/sjb/index.php"
)


Step 2. Connecting config file


For connecting file /home/user/www/sjb/lighttpd.url.rewrite.conf to lighttpd config one of the following methods can be used:

  • Add symbolic link: ln -s /home/user/www/sjb/lighttpd.url.rewrite.conf /etc/lighttpd/conf-enabled/20-sjb.url.rewrite.conf
  • Or the following line:

"include /home/user/www/sjb/lighttpd.url.rewrite.conf"
can be added to the url handling modules section of the main lighttpd config /etc/lighttpd/lighttpd.conf


Personal tools
Toolbox