Calling web.redirect('/'), the url goes to ...:8001

10 views
Skip to first unread message

gregp...@gmail.com

unread,
Jun 11, 2007, 10:44:28 PM6/11/07
to web.py
http://www.utilitymill.com works, but when I call web.redirect('/'),
the url goes to http://www.utilitymill.com:8001/

Why would it be doing this? How do I fix it?

Thanks,

Greg

gregp...@gmail.com

unread,
Jun 12, 2007, 12:16:18 AM6/12/07
to web.py
On Jun 11, 10:44 pm, "gregpin...@gmail.com" <gregpin...@gmail.com>
wrote:
> http://www.utilitymill.comworks, but when I call web.redirect('/'),
> the url goes tohttp://www.utilitymill.com:8001/

>
> Why would it be doing this? How do I fix it?

I guess I was using older code. So I replaced http.redirect with the
latest code I found from http://webpy.org/svn/trunk/web/http.py.

But now web.redirect('/') goes to http://www.utilitymill.com/code.py/
which still isn't what I want. I want http://www.utilitymill.com/.

Let me know.

-Greg


gregp...@gmail.com

unread,
Jun 12, 2007, 12:28:32 AM6/12/07
to web.py
BTW, I'm on Apache/FastCGI at Grokthis.

>From reading the code in webapi.py, it looks like I may need to
specify REAL_SCRIPT_NAME, but I'm not sure how to do this? Or I'm
hoping there's a standard solution to this issue. Is it just a bug?

-Greg

gregp...@gmail.com

unread,
Jun 12, 2007, 10:01:19 AM6/12/07
to web.py
I'm stuck on this. If there's no official solution, should I submit
it as a bug?

-Greg

dou...@gmail.com

unread,
Jun 12, 2007, 10:01:36 AM6/12/07
to web.py
>From http://new.webpy.org/install

Apache

[...]

.. with FastCGI

(...) and point your browser to http://example.com/code.py/. Don't
forget the trailing slash, otherwise you'll see a not found message
(because the urls list you defined do not match anything). To make
things work without having to enter code.py, enable mod_rewrite rules
(see below).

[...]

mod_rewrite Rules for Apache

Add the following rules to the .htaccess file:

<IfModule mod_rewrite.c> RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/icons
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
RewriteRule ^(.*)$ code.py/$1 [PT]
</IfModule>

If the code.py is in the subfolder myapp/, adjust the RewriteBase to
RewriteBase /myapp/. If you have static files like CSS files and
images to pass through, duplicate the line with the icons for each
path you want to allow.


I haven't tried this, I'm using lighttpd, but I assume it works.

dou...@gmail.com

unread,
Jun 12, 2007, 10:04:20 AM6/12/07
to web.py
Wait, I don't think that answers your question at all.

Damn, sorry.

Aaron Swartz

unread,
Jun 12, 2007, 11:12:34 AM6/12/07
to we...@googlegroups.com
> >From reading the code in webapi.py, it looks like I may need to
> specify REAL_SCRIPT_NAME, but I'm not sure how to do this? Or I'm
> hoping there's a standard solution to this issue. Is it just a bug?

I think you can do this by using Apache's SetEnv command:

SetEnv REAL_SCRIPT_NAME /path/goes/here

gregp...@gmail.com

unread,
Jun 12, 2007, 12:20:25 PM6/12/07
to web.py

Thanks, I'll try this ASAP. Any idea what '/path/goes/here' should
be?

-Greg

Tommi Raivio

unread,
Jun 12, 2007, 12:34:39 PM6/12/07
to we...@googlegroups.com
> Any idea what '/path/goes/here' should be?

If you had to solve this by yourself, from where would you start?

gregp...@gmail.com

unread,
Jun 14, 2007, 12:22:34 AM6/14/07
to web.py
On Jun 12, 12:20 pm, "gregpin...@gmail.com" <gregpin...@gmail.com>
wrote:

I added this line to my .htaccess access file:
SetEnv REAL_SCRIPT_NAME http://www.utilitymill.com

but it didn't seem to have any effect.

There should be a way a to fix this in the code anyway. Let's see if
we can figure this out. Here's how the relevant part of http.redirect
works:
if url.startswith("/"):
newloc = web.ctx.homepath + url
else:
newloc = url

Since I'm sending it '/', I'm triggering the first option. I also
determined that my web.ctx.homepath is /code.py.

web.ctx.homepath seems to be set in webapi.py in the function
_load(env). Here's the relevant line:
ctx.homepath = os.environ.get('REAL_SCRIPT_NAME',
env.get('SCRIPT_NAME', ''))

For me, os.environ is missing REAL_SCRIPT_NAME and, now here's where I
run into trouble, my globals() don't have a 'SCRIPT_NAME' key and I
think env comes from globals() from code.py? I'm pretty confused on
that point. Where does env come from exactly?

Thus since web.ctx.homepath seems to always be wrong, I found changing
my http.redirect function to work like this works fine everywhere:

def redirect(url, status='301 Moved Permanently'):
"""
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 = url
web.ctx.status = status
web.ctx.output = ''
web.header('Content-Type', 'text/html')
web.header('Location', newloc)

Should this be the new function? Or does the old way handle something
I'm missing? It seems to me that everyone would have the problem I
was having with the old code?

-Greg

Tommi Raivio

unread,
Jun 14, 2007, 12:58:31 AM6/14/07
to we...@googlegroups.com
gregp...@gmail.com wrote:

> For me, os.environ is missing REAL_SCRIPT_NAME and, now here's where I
> run into trouble, my globals() don't have a 'SCRIPT_NAME' key and I
> think env comes from globals() from code.py? I'm pretty confused on
> that point. Where does env come from exactly?


http://www.python.org/dev/peps/pep-0333/#environ-variables

Anand

unread,
Jun 14, 2007, 1:03:59 AM6/14/07
to we...@googlegroups.com

On 14-Jun-07, at 9:52 AM, gregp...@gmail.com wrote:

>
> On Jun 12, 12:20 pm, "gregpin...@gmail.com" <gregpin...@gmail.com>
> wrote:
>> On Jun 12, 11:12 am, "Aaron Swartz" <m...@aaronsw.com> wrote:
>>
>>>>> From reading the code in webapi.py, it looks like I may need to
>>>> specify REAL_SCRIPT_NAME, but I'm not sure how to do this? Or I'm
>>>> hoping there's a standard solution to this issue. Is it just a
>>>> bug?
>>
>>> I think you can do this by using Apache's SetEnv command:
>>
>>> SetEnv REAL_SCRIPT_NAME /path/goes/here
>>
>> Thanks, I'll try this ASAP. Any idea what '/path/goes/here' should
>> be?
>
> I added this line to my .htaccess access file:
> SetEnv REAL_SCRIPT_NAME http://www.utilitymill.com

REAL_SCRIPT_NAME should be set to empty string.
Apache passes SCRIPT_NAME as /code.py. Unless REAL_SCRIPT_NAME is set
webpy uses that as homepath.

Reply all
Reply to author
Forward
0 new messages