cpanel中的Python Flask应用程序路由:只能访问根url

Vla*_*mir 3 python url cpanel flask

我在 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!'}
Run Code Online (Sandbox Code Playgroud)
mydomain.com/backend/ --> Hi there
mydomain.com/backend/test --> 404
mydomain.com/backend/<any_other> --> 404
Run Code Online (Sandbox Code Playgroud)

我敢打赌在到达脚本之前还有其他一些服务返回 404。backend/我在 中找不到任何参考public_html/.htaccess。依赖关系正常(没有包抱怨)。

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

谢谢!

Ps发现类似的问题没有答案

小智 5

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

RewriteEngine on  
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]
Run Code Online (Sandbox Code Playgroud)

这为我解决了这个问题