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:

Redirect: http://www.mydomain.com/images/*

To: http://cdn.mydomain.com/images/*

The format for Lighttpd redirects is:

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

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

url.redirect = ( "^www.mydomain.com/images/(.*)$" => "http://cdn.mydomain.com/images/$1" )

Any pointers gratefully received.

Thanks

2 Replies

Take out the "www.mydomain.com" 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"] =~ "www.mydomain.com" {

server.document-root = "/var/www/mydomain.com/public_html"

server.errorlog = "/var/log/lighttpd/mydomain.com.error.log"

url.redirect = ( "^/images/(.*)$" => "http://cdn.mydomain.com/images/$1" )

}

Thanks again.

Reply

Please enter an answer
Tips:

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] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct