I have a lighttpd server running which has an SSL certificate installed. I would, due to certain reasons, like to forward all https: //www. requests to http: //www.

My lighttpd code looks like as follows:

$SERVER["socket"] == ":443"
   ssl.engine = "enable"
   ssl.pemfile = "/path/to/pem/file"
   ssl.ca-file = "/path/to/ca/file"
   HTTP["host"] =~ "^www\.(.*)$" {
       url.redirect = ("^/(.*)" => "http://www.%1$1")

Can you please point out the problem here. Another thing, what is the difference between %1 and $1 ?

  • Hi would you mind giving a bit more detail on what your are trying to achieve? User => URL:example.com => redirect to => example.com. Why? What site or URL needs to be secured? Thanks,
    – Danie
    Nov 20, 2012 at 7:58
  • Hi Danie, I'd like to redirect https: //www.example.com to http: //www.example.com
    – chochim
    Nov 20, 2012 at 8:15
  • @chochim but why?
    – j0k
    Nov 20, 2012 at 9:22

1 Answer 1


I have used this one:

$HTTP["scheme"] == "https" {
        $HTTP["host"] =~ "example.com" {
                url.redirect = ( "^/(.*)" => "http://www.example.com/$1" )

But be careful, some browser keep in mind that a website use https. So it will always try to access the https version no matter the redirect that send the webserver. I have tried this case and Firefox / Chrome told me that my website goes into an infite redirect loop. But when I curl my website on https, I got a 301 to http. And on http a 200.

So it's hard to test ...

For your second question, it's in the doc:

Note that the "%1" in the url.redirect target refers to the parenthesized subexpression in the conditional regexp (.*). It does not necessarily have the meaning that "%1" would have in evhost.path-pattern (where it would mean 'top-level domain'). If url.redirect is specified within a regex conditional, % patterns are replaced by the corresponding groups from the condition regex. %1 is replaced with the first subexpression, %2 with the second, etc. %0 is replaced by the entire substring matching the regexp. See above and below for examples using % patterns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.