Lighttpd And Wordpress SEO Friendly Permalinks

About Us

SEO Web Tips is a regularly updated blog providing search engine optimization tips, tricks and tutorials. We hope you will find many useful web design and development ideas here as well. Thanks for dropping by and please consider subscribing to our blog feed or better subscribing by email for daily updates. More »




Lighttpd And Wordpress SEO Friendly Permalinks

Wordpress permalinks are the permanent URLs to weblog posts, categories and such. The URL to each post should be permanent and never change - hence permalink. They are used by other people as well as search engines to link to your posts. One of important factors for SEO (see SEO Explained) is the URL. If your post’s URL contains relevant keywords, your post will naturally rank better. Wordpress default permalinks will work flawlessly in all server environments. However, they contain no keywords, and thus are very bad for SEO. Fortunately, Wordpress offers almost unlimited possibilities to modify your blog’s permalinks. Just log in and go to Settings - Permalinks.

Wordpress SEO friendly permalinks
You can choose from various permalink structures but none of them is optimal. Instead, choose a custom permalink structure option, fill in /%postname%/ and save the changes. WordPress will generate rewrite rules and insert them into the proper .htaccess file. That is if a blog is running on Apache webserver.

Lighttpd

What if the blog is running on Lighttpd (Lighty) webserver? Obviously, Lighttpd doesn’t support .htaccess and mod_rewrite. There are few possible ways how to achieve pretty URLs in Lighttpd - I will demonstrate two solutions.

Without Rewrite

Go to Design - Theme Editor and make sure your theme has a 404 page (404.php file). If not, just copy the 404.php file from default Kubrick theme. Open the 404 template and add this line right at the beginning of the file:

<?php header("HTTP/1.1 404 Not Found"); ?>

This makes sure pages that are not found do send 404 response headers. That is important for search engine bots.

Finally, edit a Lighttpd configuration file. Most of the time it is located in /etc/lighttpd/conf/ folder but it depends on your server’s OS and configuration. If you don’t know where to look for it, contact your web hosting provider and kindly ask - I’m sure they will help you. Once you know where your config file is located, add this line to virtual host section:

server.error-handler-404 = "/index.php"

Now your SEO friendly permalinks should work.

With Rewrite

Another solution is to manually insert rewrite rules into the Lighttpd configuration file:

url.rewrite-once = (
  "^/(wp-.+).*/?" => "$0",
  "^/(sitemap.xml)" => "$0",
  "^/(xmlrpc.php)" => "$0",
  "^/keyword/([A-Za-z_0-9\-]+)/?$" => "/index.php?keyword=$1",
  "^/.*?(\?.*)?$" => "/index.php$1"
)


If you need to exclude some folder from rewriting, just add this line:

"^/folder-excluded-from-rewriting/.*/?" => "$0",

Here are rewrite rules used on this blog (I have excluded folders images and temp from rewriting). They work just fine on WP 2.5.1:

url.rewrite-once = (
  "^/(wp-.+).*/?" => "$0",
  "^/images/.*/?" => "$0",
  "^/temp/.*/?" => "$0",
  "^/(sitemap.xml)" => "$0",
  "^/(xmlrpc.php)" => "$0",
  "^/keyword/([A-Za-z_0-9\-]+)/?$" => "/index.php?keyword=$1",
  "^/.*?(\?.*)?$" => "/index.php$1"
)

Other Possible Solutions

Wordpress permalinks with Lighttpd #3 - tested with WP 2.3 and 2.5
Wordpress permalinks with Lighttpd #4 - only works on Lighttpd 1.4.2+

  1. Renier Says:   

    Great post. My site runs on Wordpress and I’ve always wanted to know how to make my urls SEO friendly. And it works. Thanks

Name (required) 
Email (required) (will not be published) 
Website 
Comment (all comments will be manually reviewed before approval)