我一直很难在 CGI 环境中使用 Bottle.py 正确返回简单的索引 / 以外的任何内容。当我尝试返回 /hello 时,我收到 404 响应。但是,如果我请求 /index.py/hello

import bottle
from bottle import route

@route('/')
def index():
    return 'Index'

@route('/hello')
def hello():
    return 'Hello'

if __name__ == '__main__':
    from wsgiref.handlers import CGIHandler
    CGIHandler().run(bottle.default_app())

这是我的 .htaccess 文件

DirectoryIndex index.py
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.py/$1  [L]
</ifmodule>

我从这里复制了大部分代码,因为我正在使用 DH,它似乎相关: http://blog.coderonfire.com/2010/02/running-bottle-python-micro-framework.html

谢谢你的帮助。

有帮助吗?

解决方案

问题是 <ifmodule> block 与您的 Apache 服务器无关,并且 mod_rewrite 的指令不起作用。从以下内容开始 .htaccess 然后如果您有需要,请根据您当前的 apache 版本添加该块。

DirectoryIndex index.py
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.py/$1  [L]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top