PivotX is a great open source blogging CMS. While PivotX is able to handle SEO friendly permalink URLs, it only comes with mod_rewrite rules specific to Apache. Here I show you how to convert those rules for use with Lighttpd.
Luckily the conversion from the PivotX example.htaccess to
Lighttpd mod_rewrite rules is very easy. This requires you to
have admin access on your server and be able to edit the Lighttpd config file
(i.e. normally located at /etc/lighttpd/lighttpd.conf).
First I suggest you get familiar with the syntax and capabilities of Lighttpd's mod_rewrite module.
NOTE 1: The rules I've converted here are only for PivotX. Adding rules for old-school Pivot (no-X) URLs are easy to integrate if needed.
NOTE 2: My PivotX installation is located at /blog under my web
root. You will have to change that accordingly if your install is located in a
different directory or even directly under the root. Simply change all
references to /blog with your location.
Here is the original PivotX Apache rewrite rule for an entry:
RewriteRule ^entry/(.*)$ index.php?e=$1&rewrite=entry [L,QSA]
This rule states:
-
If the original URL does not match
^entry/then skip it. The carrot denotes thatentry/is at the beginning of the rest of the URL after the path where the htaccess file is located. Confused? For example with my install under/blogthis line would match/blog/entry/. -
Save all the trailing URL bits up to the end of the URL located after
entry/into the variable$1. The trailing$in the rule denotes the end of the URL. -
Rewrite the URL as
index.php?e=$1&rewrite=entry. Note the$1in the rewrite which gets replaced with the URL bits previously saved. -
The flag
[L]means stop rewriting this URL. If this was not specified then Apache would recursively rewrite the URL again. - Finally, Apache then passes the rewritten URL to PivotX
Here is the equivalent Lighttpd rewrite rule for an entry:
url.rewrite-once = ( "^/blog/entry/(.*)/trackback/?$" => "/blog/index.php?trackback&e=$1&rewrite=entry", )
As you can see the semantics are very similar and all we had to do is tweak how
the rule was specified. Note the use of url.rewrite-once. This
tells Lighttpd to only rewrite a URL once so ordering of rules is important.
Here are the final rewrite rules for Lighttpd. You can easily match all these up with those inside PivotX's example htaccess. Make special note of the final rule which will pass any non-matched URLs to PivotX and result in a 404.
url.rewrite-once = (
"^/blog/archive/(.*)$" => "/blog/index.php?uri=$1&rewrite=archive",
"^/blog/([0-9]{4})[/-](.*)/trackback/?$" => "/blog/index.php?trackback&uri=$1/$2&rewrite=archive",
"^/blog/entry/(.*)/trackback/?$" => "/blog/index.php?trackback&e=$1&rewrite=entry",
"^/blog/([0-9]{4})[/-](.*)$" => "/blog/index.php?uri=$1/$2&rewrite=archive",
"^/blog/entry/(.*)$" => "/blog/index.php?e=$1&rewrite=entry",
"^/blog/page/(.*)$" => "/blog/index.php?uri=$1&rewrite=page",
"^/blog/tag/(.*)$" => "/blog/index.php?t=$1&rewrite=tag",
"^/blog/tags/?$" => "/blog/index.php?x=tagpage",
"^/blog/search/(.*)$" => "/blog/index.php?q=$1&rewrite=search",
"^/blog/search$" => "/blog/index.php?rewrite=search",
"^/blog/visitor(/([^/]*)/?)?$" => "/blog/index.php?x=visitorpage&w=$2",
"^/blog/category/(.*)$" => "/blog/index.php?c=$1&rewrite=category",
"^/blog/weblog/(.*)$" => "/blog/index.php?w=$1&rewrite=archive",
"^/blog/author/(.*)$" => "/blog/index.php?u=$1&rewrite=author",
"^/blog/browse/(.*)$" => "/blog/index.php?o=$1&rewrite=offset",
"^/blog/rss(/([^/]*)/?)?$" => "/blog/index.php?feed=rss&w=$2",
"^/blog/atom(/([^/]*)/?)?$" => "/blog/index.php?feed=atom&w=$2",
"^/blog/(([a-z0-9_-]+)(/([a-z0-9_-]*))?)$" => "/blog/index.php?uri=$1&rewrite=page",
)
Edit: Note if you use the XML Sitemap extension then also add
the following to the above url.rewrite-once block. Thanks
Paolo for catching this.
"^/blog/sitemap.xml$" => "/blog/index.php?xml_sitemap"
Happy blogging!
rss