Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

Python flask app routing in cpanel: can only access root url

I have a python app set up in cPanel. I have set the app URL to backend and when I query mydomain.com/backend/ it gives back the app's root view (which is just an html "hello there").

The rest of the endpoints are the ones I need but I get back a 404 on every other URL

@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

I would bet there's some other service returning the 404 before reaching the script. I could not find any reference to backend/ in the public_html/.htaccess. Dependencies are ok (no package complains).

My privileges on the server are very limited. Any pointers would be appreciated.

Thanks!

Ps found a similar question with no answers

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the following rules to your .htaccess in the directory of your application url

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

that solved this issue for me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...