mod.redirect and web.py?

35 views
Skip to first unread message

KenCorey

unread,
Oct 20, 2009, 11:02:34 AM10/20/09
to web.py
Hiya,

I'm hoping someone can help.

I've successfully been using web.py originally installed with the
instructions from http://webpy.org/install.

I just got my shiny new https server working. Urls were working on
both http://clicksafety.co.uk (or http://www.clicksafety.co.uk) and
https://www.clicksafety.co.uk.

I'd like to use a redirect rule like this:

# This is a mod redirect rule to force www.
$HTTP["host"] =~ "^clicksafety\.co\.uk$" {
url.redirect = ( "^/(.*)" => "https://www.clicksafety.co.uk/$1" )
}

The intent being to force *all* accesses through https://www.clicksafety.co.uk.

The problem is that the url is rewritten as "https://
www.clicksafety.co.uk/testapp.py/testapp.py/", which, of course, fails
because the url is not recognised. All links are based on this, and
they fail as well. (If I pull the "/testapp.py/testapp.py" out of
that URL then the seb site works as before.

It seems as if "REAL_SCRIPT_NAME" needs to be set for redirects, as
well as rewrites.

Any ideas?

-Ken

Hraban Luyat

unread,
Oct 20, 2009, 11:17:36 AM10/20/09
to we...@googlegroups.com

Hi Ken,

You can match that hostname with `== "clicksafety.co.uk"' in Lighttpd.

Regarding your problem: that is strange, when you make Lighttpd redirect
it does not do anything with web.py at all, it does not even know if the
URL is legal. I do the same for all my domains, but the other way
around: no www. Here is an excerpt from my config file:

# BEGIN NOPHILOSOPHY
} else $HTTP["host"] == "www.nophilosophy.com" {
url.redirect = ("^/(.*)$" => "http://nophilosophy.com/$1" )
} else $HTTP["host"] == "nophilosophy.com" {
server.document-root = "/a/boao/home/emilia/nophilosophy.com/static"
fastcgi.server = ( "/" =>
(( "bin-path" => "/a/boao/home/emilia/nophilosophy.com/code.py",
"socket" => "/tmp/fastcgi-py-nophilosophy.com.socket",
"check-local" => "disable",
"bin-environment" => ("REAL_SCRIPT_NAME" => "")
))
)
# Disable fcgi for resources with an extension (except /sitemap.xml).
$HTTP["url"] =~ "^.+\..{3,4}$" {
$HTTP["url"] != "/sitemap.xml" {
expire.url = ("" => "access 1 days")
fastcgi.server = ()
}
}
# END NOPHILOSOPHY

That part takes care of the nophilosophy.com domain, www. and non-www.
Hope it helps!

Greetings,

Hraban

KenCorey

unread,
Oct 20, 2009, 11:39:01 AM10/20/09
to web.py
Hrm...that's interesting. What's the 'else' clause a part of? What's
processing this file that can handle if/then/else? I get errors if I
try to put an 'if' in.

I have my mod.redirect rules in the standard 10-fastcgi.conf file.

-Ken

Hraban Luyat

unread,
Oct 20, 2009, 11:42:20 AM10/20/09
to we...@googlegroups.com
'T is part of a big if elif elif elif elif else clause for host-name
based virtual hosting. Many of these hosts have peculiar, specific
configuration tweaks, so using a vhost lighttpd module is no good for
me. Lighttpd configuration looks like this:

if $HTTP[...] ... {
...
} else ... {
...
}

Peace!

Greetings,
Hraban Luyat
Reply all
Reply to author
Forward
0 new messages