首页 > 解决方案 > cpanel中的Python烧瓶应用程序路由:只能访问root url

问题描述

我在 cPanel 中设置了一个 python 应用程序。我已将应用程序 URL 设置为backend,当我查询时mydomain.com/backend/,它会返回应用程序的根视图(这只是一个 html“你好”)。

其余端点是我需要的,但我在每个其他 URL 上都返回 404

@app.route('/')
def hello_world():
  logger.debug("Hi there")
  return "<h1 style='color:red'>Hi there</h1>"

@app.route('/test', methods=['POST','GET'])
def test():
    logger.info("Got test request")
    return {'ok' : 'success!'}
mydomain.com/backend/ --> Hi there
mydomain.com/backend/test --> 404
mydomain.com/backend/<any_other> --> 404

我敢打赌,在到达脚本之前,还有其他一些服务会返回 404。我backend/public_html/.htaccess. 依赖关系没问题(没有包抱怨)。

我在服务器上的权限非常有限。任何指针将不胜感激。

谢谢!

ps发现了一个类似的问题没有答案

标签: pythonflaskurlcpanel

解决方案


将以下规则添加到应用程序 url 目录中的 .htaccess

RewriteEngine on  
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

为我解决了这个问题


推荐阅读