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.

12 comments

  • avatar
    Cliff M wrote this comment on Aug. 31, 2010, 7:17 p.m.
    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
    • avatar
      nicolas wrote this comment on Sept. 1, 2010, 9:13 a.m.
      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
  • avatar
    Wrozka Akima wrote this comment on Sept. 10, 2010, 7:37 a.m.
    Thanks
    Reply to this comment
  • avatar
    Paul Chauvet wrote this comment on Sept. 13, 2010, 10 p.m.
    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
    • avatar
      nicolas wrote this comment on Sept. 14, 2010, 12:26 a.m.
      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
  • avatar
    Rafael wrote this comment on Sept. 28, 2010, 2:11 p.m.
    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
  • avatar
    Erwin wrote this comment on March 1, 2011, 5:19 a.m.
    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
  • avatar
    Erwin wrote this comment on March 1, 2011, 1:08 p.m.
    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
  • avatar
    Umit wrote this comment on Dec. 6, 2011, 11:22 p.m.

    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

Start a new thread

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