Wednesday, October 3, 2012

WordPress Rewrite on Lighttpd

WordPress Rewrite on Lighttpd
 
 สำหรับคนที่ใช้ kloxo แล้วเลือกใช้ Lighttpd เป็น Web Server ครับ   เหตุที่เขียนเรื่องนี้ เพราะวันนี้ได้ลองลง WP ไว้บนโดเมนอักหนึ่ง (ของชาวบ้านเขา) แล้วเจ้า htaccess ดันไม่ทำงานบน Lighttpd ผมเลยต้องนั่งแก้ยาวเลย ดูภาพเอาง่ายกว่าครับ (ขี้เกียจอธิบาย) ขั้นตอนที่สอง url.rewrite-final = ( # Exclude some directories from rewriting “^/(wp-admin|wp-includes|wp-content|gallery2)/(.*)” => “$0″, “^/(.*.php)” => “$0″, “^/(.*)$” => “/index.php/$1″ ) แล้วกด Update ซะ เท่านั้นก็เพียงพอแล้วครับ     ขอขอบคุณ Teetenblog.com ที่เป็นหนูทดลองยาให้ O_o iChethost.ez.lv โฮสราคาประหยัด อยู่กันเหมือนญาติ


This blog now runs on a Lighttpd (Lighty) webserver instead of Apache, and this means the configuration for ‘pretty URLs’ or permalinks of WordPress doesn’t work like it used to.
(As you might have noticed, I use permalinks like /2007/02/this-is-permalink/)

Whereas WordPress can automatically adapt the Apache .htacccess file to something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

it does not do anything automatically for your Lighty .conf configuration file (which is logical, since an application should not be allowed to mess with a central config file).

So what you have to use is:
  1. a WordPress blog installed in the root of your (sub-) domain:
    $HTTP["host"] =~ "{yourdomain}" {
    var.app = "{yourdomain}"
    accesslog.filename = base + "/logs/" + app + ".access.log"
    server.errorlog = base + "/logs/" + app + ".error.log"
    load php app
    url.rewrite = (
    "^/(wp-.+).*/?" => "$0",
    "^/(sitemap.xml)" => "$0",
    "^/(xmlrpc.php)" => "$0",
    "^/(.+)/?$" => "/index.php/$1"
    )
    }
  2. a WordPress blog installed in a subfolder (e.g. /blog/)
    $HTTP["host"] =~ "{yourdomain}" {
    var.app = "{yourdomain}"
    accesslog.filename = base + "/logs/" + app + ".access.log"
    server.errorlog = base + "/logs/" + app + ".error.log"
    load php app
    url.rewrite = (
    "^/?$" => "/blog/index.php",
    "^/blog/(wp-.+)$" => "$0",
    "^/blog/xmlrpc.php" => "$0",
    "^/blog/sitemap.xml" => "$0",
    "^/blog/(.+)/?$" => "/blog/index.php/$1"
    )
    }
The xmlrpc.php rule is necessary for external access (like, publishing from del.icio.us or Flickr), and the sitemap.xml file is something for Google Sitemaps.
For those stubborn visitors who always precede their URLs with www, you can also add a redirect:

$HTTP["host"] =~ "www.blog.forret.com" {
url.redirect = ( ".*" => "http://blog.forret.com")
}

0 comments:

Post a Comment

 
Design by Laikeng | Bloggerized by Storesu - sutoday | Court