os.environ['REAL_SCRIPT_NAME'] = '/webpy_bug_report/'
This environment is the source for the prefixes of webpy's redirects.
I would love if there would be a solution that works across all web servers and
systems, I do not have enough experience with different setups though.
Maybe the easiest addition to webpy would be a web.config setting like
"base_url" that would be used in preference over the environment variable.
Bests,
Dragan
--
http://noobz.cc/
http://digitalfolklore.org/
http://contemporary-home-computing.org/1tb/
> homepath � The part of the path requested by the user which was trimmed off
> the current app. That is homepath + path = the path actually requested in
> HTTP by the user. E.g. /admin This seems to be derived during startup from
> the environment variable REAL_SCRIPT_NAME. It affects what web.url() will
> prepend to supplied urls. This in turn affects where web.seeother() will go,
> which might interact badly with your url rewriting scheme (e.g. mod_rewrite)
"This seems to be derived from environment variable REAL_SCRIPT_NAME."
Seems? :)
All redirecting http resonses are handled via the Redirect class in webapi.py:
class Redirect(HTTPError):
"""A `301 Moved Permanently` redirect."""
def __init__(self, url, status='301 Moved Permanently', absolute=False):
"""
Returns a `status` redirect to the new URL.
`url` is joined with the base URL so that things like
`redirect("about") will work properly.
"""
newloc = urlparse.urljoin(ctx.path, url)
if newloc.startswith('/'):
if absolute:
home = ctx.realhome
else:
home = ctx.home
newloc = home + newloc
headers = {
'Content-Type': 'text/html',
'Location': newloc
}
HTTPError.__init__(self, status, headers, "")
Here we have the variable 'realhome' which is assigned in application.py:
ctx.homedomain = ctx.protocol + '://' + env.get('HTTP_HOST', '[unknown]')
ctx.homepath = os.environ.get('REAL_SCRIPT_NAME', env.get('SCRIPT_NAME', ''))
ctx.home = ctx.homedomain + ctx.homepath
#@@ home is changed when the request is handled to a sub-application.
#@@ but the real home is required for doing absolute redirects.
ctx.realhome = ctx.home
So probably, changin ctx.realhome would help. I have no experience with
sub-applications though.
It would be great if anybody knowledgeable could chime in and recommend the best
technique for setting the redirect base.
Bests,
Dragan