Redirect with lighttpd and fastcgi on Django App
url.rewrite-once
triggers before url.redirect
, and $HTTP["host"] =~ “domain\.com"
matches www.domain.com
too.
So it first rewrites (for example) http://www.domain.com/
internally to http://www.domain.com/domain.fcgi/
and then redirects the client to http://domain.com/domain.fcgi/
. The client sends a new request which gets then rewritten to http://domain.com/domain.fcgi/domain.fcgi/
and then sent to the django app.
The solution is to make the second block match only "domain.com" and not the sub-domains, i.e. $HTTP["host"] == "domain.com"
(simple comparison) or $HTTP["host"] =~ "^domain\.com"
(anchored regular expression).
Even more strict regular expressions would be $HTTP["host"] =~ "\.domain\.com(:[0-9]+)?$"
and $HTTP["host"] =~ "^domain\.com(:[0-9]+)?$"