WordPress 3.0 network lighttpd rewrite rules

I recently installed my first WordPress network on lighttpd and was looking for rewrite rules. This post is correct except for the rewrite rule for files. I supposed it's a change that was introduced in 3.0, or maybe earlier. Anyway, here are updated rewrite rules:

In your lighttpd.conf:

$HTTP["host"] =~ "domain\.com" {
    simple-vhost.default-host = "domain.com"
    include "wpmu-rewrite.conf"
}

And wpmu-rewrite.conf:

url.rewrite-once = (
    "^/(.*/)?files/$" => "/index.php",
    "^/(.*/)?files/(.*)" => "/wp-includes/ms-files.php?file=$2",
    "^(/wp-admin/.*)" => "$1",
    "^/({_0}+/)?(wp-.*)" => "/$2",
    "^/({_0}+/)?(.*\.php)$" => "/$2",
)

What's changed from the other site's example is the ms-files.php rewrite rule.

Published on June 6, 2010 at 3 p.m. by Nicolas and tagged WordPress, rewrite, WPMU, lighttpd, WordPress network. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

16 comments

  1. avatar
    wrote this comment on

    Can you provide the rewrite code for wp mu installs in a subdirectory?

    For example, my wp multisite install is in the following subdirectory
    htttp://www.mysite.com/myblogs/

    with subsequent new sites being created as "myhome" with the url being http://www.mysite.com/myblogs/myhome

    Thank you.

    Reply to this comment
    1. avatar
      wrote this comment on

      Hi Cliff, I don't use subdirectory installs myself, so I don't really know. Just look for pre-3.0 rewrite rules and fix the ms-files.php line. Should be really easy.

      Reply to this comment
  2. avatar
    wrote this comment on

    Thanks

    Reply to this comment
  3. avatar
    wrote this comment on

    This is very helpful advice! I'm still somewhat new to lighttpd but I'm switching to it for some of our WPMU sites for performance reasons.

    Thanks!

    Reply to this comment
    1. avatar
      wrote this comment on

      Yeah, I also switched to lighttpd when my old server ran out of memory too often and have been very happy every since. If you have a lot of traffic you should probably try nginx as well. It seems to be quite popular and does reverse proxying out of the box which could be useful in your case.

      Reply to this comment
  4. avatar
    wrote this comment on

    Caro Nicolas.

    Eu estou no Brasil...quero te agradecer imensamente por ter resolvido o meu problema no multisites - com a regra anterior havia problemas no upload de imagens - com a sua regra o meu problema foi resolvido - estou muito feliz - muito obrigado

    Reply to this comment
    1. avatar
      wrote this comment on

      You're welcome... I guess :-)

      Reply to this comment
  5. avatar
    wrote this comment on

    Hello,

    Will the above rules work with other permalinks? Say:

    /%post_id%/%postname%

    I see some solutions that has:

    "(\?.*)$" => "index.php$1",
    "." => "index.php"

    but would adding "." would be like a fallback if everything else fails in the rules? Like adding more burden to index.php/wordpress?

    Reply to this comment
    1. avatar
      wrote this comment on

      Did you try yet? The rules above should really cover all permalink structures.

      Reply to this comment
  6. avatar
    wrote this comment on

    Hi Nicolas,

    I did try your solution but had 404's on /%post_id%/%postname% permalinks. I'm also using sub-domain/multisites. I ended up adding:

    "." => "index.php"

    It worked but I'm not sure if this is the correct way to do it.

    Reply to this comment
  7. avatar
    wrote this comment on

    Hi Nicolas,

    After rewrite it runs my application twice. Do you know why? And if it is a normal working of lighttpd could you tell me how can detect duplicate request by using environment variables?

    Thank you,
    Reply to this comment
    1. avatar
      wrote this comment on
      Hmmm. I'm not sure what you mean?
      Reply to this comment
  8. avatar
    wrote this comment on
    hey, why the heck I can't see the post but only the comments? I really need some urgent answers, and this seems to promising, but... zonk... WTF?
    Reply to this comment
    1. avatar
      wrote this comment on
      Aaaah... sorry, there was a bug in this website's code. It's fixed by now.
      Reply to this comment
  9. avatar
    wrote this comment on
    Okay, so with the new wordpress multisite and lighttpd 1.4.x I got it working with this:

    note that I have everything installed under /blog/

    url.rewrite-if-not-file = (
    "^/blog/index\.php$" => "$0", # this does nothing, especially since index.php should be a file
    "^/blog/([_0-9a-zA-Z-]+/)?wp-admin$" => "/blog/$1wp-admin/", # this adds a / to /wp-admin
    "^/blog/$" => "$0", # this seems unnecessary, but I kept it for fun
    "^/blog/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" => "/blog/$2", # this forwards wordpress files
    "^/blog/([_0-9a-zA-Z-]+/)?(\?.*)" => "/blog/$2", # this fixes search
    "^/blog/." => "/blog/index.php"
    )

    Best of luck!

    MVirts
    Reply to this comment
    1. avatar
      wrote this comment on
      Thanks for the input. My post is pretty old, and I haven't really used lighttpd or wp in years.
      Reply to this comment

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.