現在、Python ボトルを使用して単純なスタンドアロン アプリケーションを作成しようとしています。
私のプロジェクト全体はpytest/
、私が持っている と の下にdispatch.fcgi
あり.htaccess
ます。
dispatch.fcgi
:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bottle
import os
from bottle import route, run, view
@route('<foo:path>')
@view('index')
def pytest(foo = ''):
return dict(foo=foo)
APP_ROOT = os.path.abspath(os.path.dirname(__file__))
bottle.TEMPLATE_PATH.append(os.path.join(APP_ROOT, 'templates'))
app = bottle.default_app()
if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()
.htaccess
:
DirectoryIndex dispatch.fcgi
次の URL から、対応する の値が得られますfoo
。
url.com/pytest/
> /pytest/
url.com/pytest/dispatch.fcgi
> /pytest/dispatch.fcgi
url.com/pytest/dispatch.fcgi/
> /
url.com/pytest/dispatch.fcgi/foo/bar
> /foo/bar
url.com/pytest/dispatch.fcgi/pytest/
> /pytest/
URL を統一するにはどうすればよいですか? .htaccess
ファイルまたは Python コード内で再ルーティングを処理する必要がありますか? 最もpythonicまたはベストプラクティスと見なされるものは何ですか?
Python 2.6.6、Bottle 0.11.6、Flup 1.0.2、および Apache 2.2.24 を実行しています。また、私は共有ホスティングを使用しており、mod_wsgi は問題外であることも指摘したいと思います (それが違いを生む場合)。
編集
これは私が期待するものです:
url.com/pytest/
> <redirect to url.com/pytest/dispatch.fcgi>
url.com/pytest/dispatch.fcgi
> <empty string>
url.com/pytest/dispatch.fcgi/
> /
url.com/pytest/dispatch.fcgi/foo/bar
> /foo/bar
url.com/pytest/dispatch.fcgi/pytest/
> /pytest/
この問題に取り組むためのより効率的な方法がある場合は、お知らせください。