On twitter

RT @beichen: 温家宝回应“谷歌”事件说,让外企享受到公民待遇。看来谷歌是铁定是要滚蛋了。

follow me on twitter

lighttpd rewrite rules for Wordpress permalink 6

先前由於把 Apache 換成 Lighttpd, 忘記還有 permalink 這東西, 所以 Wordpress 的 permalink 就掛點了。lighttpd 的 rewrite 好像沒有可以判斷檔案不在才做 rewrite 的條件, 又由於對 lighttpd 不熟, 只好在網路上找, 不過找到有些 rewrite rules 都嘛有問題, 所以參考一些找到的 rewrite rules, 然後修改成下面這樣 :p

url.rewrite = (
    "^/blog/?$" => "/blog/index.php",
    "^/blog/(?.*)$" => "/blog/index.php$1",
    "^/blog/(wp-.+)$" => "$0",
    "^/blog/([^.]+)/?$" => "/blog/index.php?$1",
)

目前跑的都還正常, 有問題麻煩請通知 XD

update:
用了好多天才知道, 這個 rewrite 有問題, 例如像下面這個網址重複兩個 blog 就掛點了

http://tzangms.com/blog/975

後來才重新看一下最後一個 rule, 把原本的 index.php/$1 改成 index.php?$1 就好了… hmm 我直覺上是這樣啦 XD anyway 總之這樣就正常了 XD

January 20th, 2008 Linux Tags: , ,

6 Responses to “lighttpd rewrite rules for Wordpress permalink”

  1. [...] Installing Lighttpd With PHP5 And MySQL Support On CentOS 5.0 Lighttpd-輕量級 Web Server gslin 大大:在 lighttpd 上擋圖片盜連 Lighttpd 防止圖片盜連 lighttpd rewrite rules for Wordpress permalink [...]

  2. shami says:

    你好..有個問題想請教你一下…
    因為找不到你的留言板,所以留在此篇

    我的伺服器架構是
    lighttpd當前端負載 prot80 處理靜態資料→nginx當主伺服器 prot8080 處理動態資料

    lighttpd的負載設定是:
    $HTTP["url"] !~ "\.(js|css|gif|jpg|png|ico|txt|swf|htm|html)$" {
    proxy.server = ( "" => (
    ( "host" => "127.0.0.1", "port" => 8080 )
    )
    )
    }

    rewrite rules 我是寫在nginx
    location /blog/ {
    index index.html index.php;
    if (!-e $request_filename) {
    rewrite ^/blog/(.+)$ /blog/index.php?q=$1 last;
    }
    }
    location / {
    if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
    rewrite (.*) /index.php;
    }
    }

    基本上都能正常運作,不過要進 單篇文章 就出錯了
    wp的固定網址設定是: /%post_id%.html

    參考了你的資料和一些國外資料都無法正常進到單篇文章
    不曉得你有沒有解決的方法?

  3. tzangms says:

    @shami
    我沒碰過 nginx 的 rewrite 阿 ~”~

    不過, 看了你 lighttpd 的設定, 要不要把 html 拿掉試試看? 不知道有沒有用 ~”~

  4. shami says:

    把 html 拿掉這方法我有先試過,的確是可以正常運作
    不過這樣就等於還是從 nginx 來執行 html
    所以我猜想可能是要在 lighttpd 寫 rewrite rules 讓他有辦法辨識 nginx 快取產生的 html 好讓 lighttpd 正常執行 html
    我在摸索摸索….還是謝謝你唷

    題外話…留言打字區的字好小喔….0.0

  5. tzangms says:

    @shami
    呵, 拍謝啦, 在改佈景主題, 還沒找到合適的 XD

    hmm~ 應該不是這樣內, 我看你 lighttpd 的 proxy 設定部份, 應該是非靜態檔才會送到 nginx 對吧?

    所以以下是我的猜測, 因為 html 被 lighttpd 當成靜態檔, 所以並不會送到 nginx, 所以 nginx 根本沒有收到, 也沒有辦法做 rewrite。 變成的狀況是, nginx 直接收到 html 的請求, 所以直接去找 html 檔, 但是沒找到, 你參考看看。

    也許把 wordpress 的 permalink 不要設定為 .html

  6. shami says:

    會想多加一個 lighttp 當前端負載是因為最近在研究 cos-html-cache 這個wp的快取插件
    這個插件會產生跟每篇文章相對應的 html 檔案
    例如你這篇文章是1055,就會產生一個 1055.html 檔案,網址就變成 http://tzangms.com/blog/linux/1055.html
    這樣應該算是真正的靜態檔?所以我才會想是不是能讓 lighttpd 直接調用 1055.html 這個檔案,而不需要經由 nginx 執行
    或許是我思路不太正確吧0.0
    研究研究….

Leave a Reply

Partners of Oceanic / 人生海海

jiwo sca wellmeet