title: Hosting flask app on subdomain (with WordPress hosted on main domain)
body: <p>I hope you can help with the following as I’ve been struggling to make it work for many days now.</p>
  <p>To give you a little background, I used to host a flask app on my website domain.xyz. It is hosted on namecheap and runs via the CPanel Python App.
  I then decided to also have a WordPress on the same site, so I had to move the flask to the subdomain api.domain.xyz</p>
  <p>Now, the Wordpress site works, as does the root page of the flask app (api.domain.xyz). However, all other routes of the flask give me the same error page:</p>
  <p>„ Not Found</p>
  <p>The requested URL was not found on this server.</p>
  <p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.“</p>
  <p>Im Hosting with Namencheap, and have tried many times the support, it they insist that it’s a code Problem. What am I doing wrong?</p>
  <p>Here’s the python code:</p>
  <pre><code>    #main.py
  from flask import Flask, jsonify, request, abort
  import os
  from flask import g
  import time
  import socket
  
  app = Flask(__name__, subdomain_matching=True)
  #app.config[&quot;APPLICATION_ROOT&quot;] = &quot;/api&quot;
  #app.config[&quot;DEBUG&quot;] = True
  
  @app.before_request
  def before_request():
      print(&quot;before request&quot;)
      g.start = time.time()
      
  
  @app.route('/test', subdomain=&quot;api&quot;, methods=['GET'])
  def test():
      return '''api'''
      
  @app.route('/', methods=['GET'])
  def home():
      print(&quot;HOME&quot;)
      return '''&lt;p&gt;This is the root page.&lt;/p&gt;'''
   
  
  @app.after_request
  def after_request(response):
      diff = time.time() - g.start
      print (&quot;Request time: &quot; + str(diff))
      if ((response.response) and
          (200 &lt;= response.status_code &lt; 300) and
          (response.content_type.startswith('text/html'))):
          response.set_data(response.get_data().replace(
              b'__EXECUTION_TIME__', bytes(str(diff), 'utf-8')))
      return response
  
  if __name__ == '__main__':
      app.run(host='api.domain.xyz', debug=True)
  </code></pre>
  <p>So basically, api.domain.xyz routs properly and writes „this is the root page“, while api.domain.xyz/test shows the error. In particular, not even the before_request code gets called (as I can tell from the logs), which tells me it never makes it to the code.</p>
  <p>Any help is hugely appreciated!</p>