Thanks, Dragan.

That's a novel solution.  I hadn't thought of changing an environment
variable, but it sounds like it would work.  As for a
web.config.base_url, in theory the web.homepath is supposed to do
exactly that.  As far as I can tell, it's just broken (or at least
doesn't work how I expected).

For now, I'm using the function below.  Instead of calling
web.seeother(url), I call web.seeother(make_url(url)).

If this is an acknowledged issue and a patch would be welcome, I could
probably take another shot at a more general fix that would hopefully
not have any unintended consequences.

I had also been grappling with how to handle links embedded in the
templates, but I just thought of a solution:  Put a <BASE href="http://
example.com/myapp/"> tag with the application's base URL in the <HEAD>
of the base template.

Alex





___________________________________________________________________________
def make_url(url):
    """
    Fix an apparent incompatibility between how I'm using Apache URL
rewriting
    and the web.seeother (and web.redirect, etc.) commands.

    - If input is full URL (i.e., http://example.com/blah/), return as
is.
    - If input starts with "/", treat as relative to this
application's base.
    - Otherwise, append it to the current URL, minus any ending
filename.
    """
    import urlparse, os

    if "://" not in url:
        url_parts =
list(urlparse.urlparse(web.ctx.env["REQUEST_URI"]))
        old_path = url_parts[2]

        if url.startswith("/"):
            base = os.path.basename(__file__)
            home = web.ctx.home
            if home.endswith(base) and not
old_path.endswith(__file__):
                home = home[:0-len(base)]
            url = home.rstrip("/") + url
        else:
            new_path = os.path.normpath(os.path.join(old_path, url))
            url_parts[2] = new_path
            url = urlparse.urlunparse(url_parts)
    return url
___________________________________________________________________________







On Jan 30, 4:28 am, Dragan Espenschied <d...@a-blast.org> wrote:
> This redirecting problem is indeed annoying, I usually "solve" it by changing 
> an
> environment variable, for example like this:
>
> 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
>
> Am 29.01.2012 21:26, schrieb Alex Quinn:
>
>
>
>
>
>
>
>
>
> > Below is a stripped down example that illustrates the problem.  If I
> > go tohttp://example.com/webpy_bug_report/it works fine.  If I go to
> >http://example.com/webpy_bug_report/redirect/I expect to be
> > redirected tohttp://example.com/webpy_bug_report/but instead I am
> > redirected tohttp://example.com/webpy_bug_report/redirect_problem.py/.
> > I've tried this under plain CGI as well as FastCGI.
>
> > Upon further testing, I realized my current fix doesn't quite work.
> > If this is indeed a bug, I'd be happy to take another try at fixing
> > it.  However, it seems like this would have come up for others
> > before.  I couldn't find anything in the list archives or the issue
> > tracker.  If I'm doing something wrong or if I missed a solution
> > online somewhere, I'd be most grateful if somebody could point me in
> > the right direction.
>
> > Thanks,
> > Alex
>
> > ___________________________________________________________
> > # .htaccess
>
> > RewriteEngine on
> > RewriteBase /webpy_bug_report/
> > RewriteCond %{REQUEST_URI} !^/webpy_bug_report/favicon.ico$
> > RewriteCond %{REQUEST_URI} !^(/.*)+redirect_problem.py/
> > RewriteRule ^(.*)$ redirect_problem.py/$1 [PT]
>
> > ___________________________________________________________
> > # redirect_problem.py
>
> > import web
>
> > urls = (
> >     '/',         'index',
> >     '/redirect/','redirect'
> > )
>
> > class index:
> >     def GET(self):
> >         return "This is the index page."
>
> > class redirect:
> >     def GET(self):
> >         raise web.seeother('/')
>
> > app = web.application(urls, globals())
>
> > if __name__ == '__main__':
> >     app.run()
>
> --http://noobz.cc/http://digitalfolklore.org/http://contemporary-home-computing.org/1tb/

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to webpy@googlegroups.com.
To unsubscribe from this group, send email to 
webpy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to