Lighttpd Rewrite

Discussion in 'Site & Server Administration' started by j0ned, Nov 28, 2007.

  1. #1
    Good Day Everyone,

    I currently have a site configured that makes URLs in the following format:
    some-domain.com/?cat_id=67659&name=Natural+Therapies

    and was wondering if anyone could suggestion a lighttpd rewrite rule to output something similar to the following instead:
    some-domain.com/category/Natural-Therapies/

    This is obviously for SEO purposes. Any ideas/suggestions?
     
    j0ned, Nov 28, 2007 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are two troubles with this request as you have stated it:

    1. Rewrites can't look anything up in a database so if you're planning on pulling an article or set of articles out of your database using that cat_id then it's going to need to be in the original URL.

    2. Rewrites can't do search-and-replace so the - vs + part of the URL (in between "Natural" and "Therapies") will cause some problems. It's possible to manage a rewrite like that but it would be horrendously messy and not really very necessary.

    Solutions:
    1. Include the cat_id in the URL. Either of these would do the job:

    some-domain.com/category/Natural-Therapies/67659/
    some-domain.com/category/67659/Natural-Therapies/

    Pick whichever one you think will have the best SEO / Human Readability Optimisation qualities.

    2. Change your category names to be separated by dashes. This will mean that the final URL will be:

    some-domain.com/?cat_id=67659&name=Natural-Therapies

    which you can adjust in PHP later on if you wish.

    My memory of Lighttpd is a little rusty these days but with the changes I suggested above, I think you want something like this:
    url.rewrite=("/category/([0-9]*)/([^/]*)/" => "?cat_id=$1&name=$2")
    Code (markup):
     
    Ladadadada, Nov 29, 2007 IP