samedi 29 mars 2008

Wordpress (v2.1) permalinks and Lighttpd (v1.4)

Last days, I moved my website on a new server and I installed Lighttpd instead of Apache. The first problem I had to solve was about permalinks. It's always more comfortable to use links like :

http://www.dogguy.org/blog/%year%/%month%/%day%/%post_name%

than

http://www.dogguy.org/blog/index.php?p=%post_id%

Then, I tried to look, using Google, what people have done to avoid this issue. One solution is to redirect every query to this /blog/index.php/%year%/%month%/%day%/%post_name% , but it didn't work for me. Another one is to use _GET variables. This final solution seems pretty clean ... but it didn't work neither. So I tried to modify it to make it work. It wasn't difficult and here is the result :


$HTTP["host"] =~ "www.dogguy.org" {
url.rewrite = (
"^/blog/((wp-.+)|images).*/?" => "$0",
"^/blog/(sitemap.xml)" => "$0",
"^/blog/(xmlrpc.php)" => "$0",
"^/blog/page/([0-9]+)/?$" => "/blog/index.php?paged=$1",
"^/blog/([0-9]+)/?$" => "/blog/index.php?m=$1",
"^/blog/([0-9]+)/([0-9]+)/?$" => "/blog/index.php?m=$1$2",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/?$" => "/blog/index.php?m=$1$2$3",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/?$" => "/blog/index.php?name=$4",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/feed/?$" => "/blog/index.php?name=$4&feed=rss2",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/feed/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?name=$4&feed=$5",
"^/blog/([_0-9a-zA-Z-]+)/?$" => "/blog/index.php?page_id=$1",
"^/blog/feed/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?feed=$2",
"^/blog/comments/feed/?$" => "/blog/index.php?feed=comments-rss2",
"^/blog/comments/feed/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?feed=comments-$1",
"^/blog/(.+)/([0-9]+)/[^/]+/?/trackback/?$" => "/blog/index.php?category_name=$1&p=$2&tb=1",
"^/blog/category/(.+)/?$" => "/blog/index.php?category_name=$1",
"^/blog/category/(.+)/feed/?$" => "/blog/index.php?category_name=$1&feed=rss2",
"^/blog/category/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?category_name=$1&feed=$2",
)
}


Maybe it isn't complete enough for you ... but it suits my needs completely :) Any suggestion to enhance this piece of code is welcome.

UPDATE: I forgot trackback ! And I use this occasion to change feeds URLs and other missing things. So here is my new set of rules :


$HTTP["host"] =~ "www.dogguy.org" {
url.rewrite = (
"^/blog/((wp-.+)|images).*/?" => "$0",
"^/blog/(sitemap.xml)" => "$0",
"^/blog/(xmlrpc.php)" => "$0",
"^/blog/page/([0-9]+)/?$" => "/blog/index.php?paged=$1",
"^/blog/([0-9]+)/?$" => "/blog/index.php?m=$1",
"^/blog/([0-9]+)/([0-9]+)/?$" => "/blog/index.php?m=$1$2",
"^/blog/([0-9]+)/([0-9]+)/page/([0-9]+)/?$" => "/blog/index.php?m=$1$2&paged=$3",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/?$" => "/blog/index.php?m=$1$2$3",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/?$" => "/blog/index.php?year=$1&monthnum=$2&day=$3&name=$4",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/trackback/?$" => "/blog/wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4",
"^/blog/([0-9]+)/([0-9]+)/([0-9]+)/([_0-9a-zA-Z-]+)/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5",
"^/blog/([_0-9a-zA-Z-]+)/?$" => "/blog/index.php?page_id=$1",
"^/blog/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?feed=$2",
"^/blog/comments/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?feed=comments-$1",
"^/blog/(.+)/([0-9]+)/[^/]+/?/trackback/?$" => "/blog/index.php?category_name=$1&p=$2&tb=1",
"^/blog/category/(.+)/page/([0-9]+)/?$" => "/blog/index.php?category_name=$1&paged=$2",
"^/blog/category/(.+)/(feed|rdf|rss|rss2|atom)/?$" => "/blog/index.php?category_name=$1&feed=$2",
"^/blog/category/(.+)/?$" => "/blog/index.php?category_name=$1",
)
}

Aucun commentaire:

Enregistrer un commentaire