Why would it be doing this? How do I fix it?
Thanks,
Greg
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
>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
-Greg
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.
Damn, sorry.
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?
-Greg
If you had to solve this by yourself, from where would you start?
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
> 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?
>
> 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.