Lighttpd redirect rule for CDN (RegEx help)

Hi all

I've set up a CDN for image caching on a web site on my Linode running Lighttpd. I need a redirect rule for the images directory - but RegEx isn't my strong point. I wonder if someone could point me in the right direction?

I'd like to redirect all contents (including one level of nested directories and their contents) in the images directory on the subdomain www to the equivalent on the cdn subdomain - basically:



The format for Lighttpd redirects is:

url.redirect = ( "RegEx" => "redirect_url" )

and I've been playing (unsuccessfully) with something like:

url.redirect = ( "^*)$" => "$1" )

Any pointers gratefully received.


2 Replies

Take out the "" in that regexp – literally; remove that, but keep the ^ and / -- and you should be golden. (Obviously, you'll need to put the url.redirect inside the proper vhost instead of making it global.)

Brilliant - thank you.

Note: in order to stop a redirect loop I had to redefine the host specific to the subdomain (www) - so my host config looks like this:

$HTTP["host"] =~ "" {

server.document-root = "/var/www/"

server.errorlog = "/var/log/lighttpd/"

url.redirect = ( "^/images/(.*)$" => "$1" )


Thanks again.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct