Lighttpd rewrite help

lony

New Member
Reaction score
1
Hi everybody :)

I need some help with 2 rewrite rules, well only one actually. :)

Here's what I'm trying:
url.rewrite-once = (
"^/daily/([a-z_0-9]+).html$" => "/daily.php?day=$1",
"^/weekly/([a-z_0-9]+)-([photos|websites|web\-stats|news]).html" => "/weekly.php?month=$1&category=$2")

The first rule need to work for these example URLs:
http://lightttpd/daily/monday.html
http://lightttpd/daily/monday5.html
http://lightttpd/daily/day_of_monday_15.html

And it seems to work, however the second rule is giving me problems by not matching these urls:
http://lightttpd/weekly/week52-photos.html
http://lightttpd/weekly/the_week_of_52-web-stats.html
http://lightttpd/weekly/the_week_of_52-news.html
 

Artificial

Without Intelligence
Reaction score
326
Code:
([photos|websites|web\-stats|news])
Means "any of the characters p, h, o, t, o, s, |, w, ...". If you remove the square brackets, it would mean "any of the following strings: photos, websites, web-stats, news".

So the second one should be
Code:
"^/weekly/([a-z_0-9]+)-(photos|websites|web\-stats|news).html" => "/weekly.php?month=$1&category=$2"
And the backslash in the "web\-stats" part isn't necessary.
 

Artificial

Without Intelligence
Reaction score
326
Works for me using lighttpd 1.4.28. Here are the scripts I used to test it:

/home/felix/lighttpd.config
Code:
server.document-root = "/home/felix/"
server.port = 8080
server.modules += ("mod_rewrite", "mod_cgi")

cgi.assign = (".py" => "/usr/bin/python")

url.rewrite-once = (
    "^/daily/(\w+).html$" => "script.py?day=$1",
    "^/weekly/(\w+)-(photos|websites|web-stats|news).html$"
        => "script.py?month=$1&category=$2"
)

/home/felix/script.py
Code:
import cgi

data = cgi.FieldStorage()

# Print GET parameters in format key=value.
for d in data:
    print '{}={}'.format(d, data[d].value)

Started the server with lighttpd -Df lighttpd.config and got these responses:
Code:
felix:~$ curl localhost:8080/daily/woot.html
day=woot
felix:~$ curl localhost:8080/weekly/whaat-web-stats.html
category=web-stats
month=whaat
felix:~$ curl localhost:8080/weekly/2343-photos.html
category=photos
month=2343

What doesn't work for you? Do you get some kind of an error message?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top