Blog / WordPress/ How to Configure WordPress Permalink Rewrite Rules for Lighttpd

How to Configure WordPress Permalink Rewrite Rules for Lighttpd

Lighttpd 服务器 WordPress 永久链接(Rewrite)规则配置指南

Configuring WordPress Permalinks on Lighttpd

To enable WordPress permalinks on a Lighttpd server, you must configure the url.rewrite-once rules. The following optimized rule set correctly handles WordPress core files, static assets, and multisite requests.

Standard Rewrite Rules

Add these rules to your Lighttpd configuration file (typically lighttpd.conf) or the relevant virtual host configuration.

url.rewrite-once = (
    "^/(wp-.+)" => "$1",
    "^/([_0-9a-zA-Z-]+/)?(wp-.+)" => "$2",
    "^/([_0-9a-zA-Z-]+/)?(.*\.php)$" => "$2",
    "^/.+\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)(\?.*)?$" => "$0",
    "^/(.*)?/?files/(.*)" => "wp-includes/ms-files.php?file=$2",
    "(.+)/?$" => "/index.php$1"
)

Rule Explanation and Improvements

This rule set includes several important corrections and optimizations:

  • Fixed Syntax Error: The final catch-all rule uses the correct pattern "(.+)/?$" => "/index.php$1" to pass all other requests to index.php.
  • Updated Multisite File Handling: For WordPress Multisite uploads, the correct endpoint is wp-includes/ms-files.php, not the outdated wp-content/blogs.php.
  • Excluded Static Resources: A new rule directly serves static files (CSS, JS, images, fonts) to avoid unnecessary rewriting and improve performance.
  • Optimized Core Request Matching: Rules prioritize direct access to WordPress core files (those starting with wp-).

Configuration Steps

  1. Back up your Lighttpd configuration file.
  2. Ensure the mod_rewrite module is enabled in your configuration.
  3. Add the url.rewrite-once rules provided above.
  4. Reload or restart the Lighttpd service.
  5. In your WordPress admin panel, go to Settings > Permalinks, choose your preferred structure, and save.

Note: These rules work for standard and multisite WordPress installations. After configuration, verify that your site's front-end, admin area, and media files load correctly.

Post a Comment

Your email will not be published. Required fields are marked with *.