我在根目录中有以下 .htaccess 以启动 web.py 应用程序:
allow from all
SetHandler fcgid-script
Options +ExecCGI
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.py/$1 [PT]
一切正常,除了我无法使用 css 等访问静态文件夹。
这是app.py中的代码:
import web
from getImgUrl import search
render = web.template.render('templates/')
urls = (
'/', 'index'
)
class index:
def GET(self):
term = search()
return render.index(term[0], term[1])
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
我通过在
static
文件夹中添加 .htaccess 文件来解决:
SetHandler None
您还可以尝试上面的
RewriteRule ^static - [L]
,这意味着访问基于RewriteRule ^(.*)$ app.py/$1 [PT]
的资源时不会发生重写(/static
表示跳过进一步的重写规则处理)。