Lighttpd and wordpress setup clean SEO friendly URLs

by Vivek Gite · 8 comments

Lighttpd logo

By default WordPress uses web URIs which have question marks and lots of numbers in them; however WordPress offers you the ability to create a custom URI structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links.

Apache has .htaccess file to setup clean SEO friendly URLs using mod_rewrite module. Similarly. Lighttpd can be use mod_rewrite for writing out clean SEO friendly URLs.

Task: Single wordpress blog (documentroot) and SEO URLS

Let us assume that your blog is hosted at http://theos.in (i.e. no subdirectory) and your want pretty urls.

=> Login to your wordpress admin account

=> Go to Options > PermaLinks

=> Now select URL structure as per your need.
For example Date and name based Permalink Structure should be set as follows (remove the default /index.php/%year%/%monthnum%/%day%/%postname%/):
/%year%/%monthnum%/%day%/%postname%/

=> Click on Update Permalink structure button to save the changes.

=> Now open your lighttpd configuration file
# vi /etc/lighttpd/lighttpd.conf

=> Locate your virtual hosting configuration for your domain (theos.in) and aftter server.document-root add following line:
server.error-handler-404 = "/index.php?error=404"

At the end your configuration should look as follows:
$SERVER["socket"] == "203.xx.xx.xx:80" {
server.document-root = "/home/lighttpd/theos.in/http"
server.errorlog = "/var/log/lighttpd/theos.in/error.log"
accesslog.filename = "/var/log/lighttpd/theos.in/access.log"
server.error-handler-404 = "/index.php?error=404"
}

Save and close the file. Restart lighttpd:
# /etc/init.d/lighttpd

Task: Multiple wordpress blogs single documentroot and SEO URLS

Let us assume that you have multiple blogs hosted under single document root called /home/lighttpd/ as follows:
/home/lighttpd/blog1 (http://theos.in/blog1)
/home/lighttpd/blog2 (http://theos.in/blog1)
...
....
..

First, Login to both blogs and setup Permalink structure as per your requirements. Open /etc/lighttpd/lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf

Find your domains configuration section and append lines as follows:
$HTTP["url"] =~ "^/blog1($|/)" { server.error-handler-404 = "/blog1/index.php?error=404" }
$HTTP["url"] =~ "^/blog2($|/)" { server.error-handler-404 = "/blog2/index.php?error=404" }

Save and close the file. Restart lighttpd:
# /etc/init.d/lighttpd restart

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 8 comments… read them below or add one }

1 ali 04.12.07 at 12:39 pm

It was really surprising to see that the only necessary step to take was to address the 404, definitely much easier than Apache :)

Thank you for the tip.

2 BOK 04.29.08 at 7:14 pm

Indeed amazingly simple!
I spent an hour or more on multiple line configs while this was all that was needed… Thanks!

3 vivek 04.29.08 at 11:18 pm

Please make sure you have 404.php in template directory to send 404 stats when you got actual error 404.

4 Rick 05.24.09 at 3:05 am

Thanks!
Very userful!

5 rbtok 07.01.09 at 7:28 pm

finally i found the simplest and useful way to solve this problem

thanks pal!

6 Calvin 09.17.09 at 7:27 pm

I had spent hours trying to get the permalinks working, this did the job in under 2 minutes.

Thanks so much :-)

Calvin

7 @sinergepress 11.29.09 at 9:50 am

Thanks, solved the problem pretty neatly! Cheers

8 This 01.06.10 at 6:16 pm

As a webdesigner myself , I’m extremely glad to see that another individual thought to post this topic.

Quite a few people out there just don’t grasp the concept of what all is needed in this industry, and I think also we are many times underrated
or taken for granted. Never the less I’m immensely glad to see that you may feel the same way I do , thanks so much for your blog!

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: