title: Retain URL in browser with Flask redirect
body: <p>I have a Bokeh server application deployed on Heroku, with multiple styles that result in cumbersome URLs. For example: <a href="https://invlabs-bokehserver.herokuapp.com/avyview?style=snowpacktracker" rel="nofollow noreferrer">https://invlabs-bokehserver.herokuapp.com/avyview?style=snowpacktracker</a></p>
  
  <p>I am using Flask deployed on Heroku to take extensions from a simple custom domain (<a href="http://www.snowpacktracker.com" rel="nofollow noreferrer">www.snowpacktracker.com</a>) and redirect to a second Heroku app that runs a Bokeh server and returns the html content. The relevant Flask app code:</p>
  
  <pre><code>from flask import Flask, redirect
  
  app = Flask(__name__)
  @app.route('/')
  def index():
    return redirect(url_for("btac"), code=302)
  
  @app.route('/btac')
  def func1():
    return redirect("https://invlabs-bokehserver.herokuapp.com/avyview?style=snowpacktracker", code=302)
  
  @app.route('/btac/historic') 
  def btac_historic():
    return redirect("https://invlabs-bokehserver.herokuapp.com/avyview", code=302)
  
  if __name__ == '__main__':
    app.run()
  </code></pre>
  
  <p>I would like the original URL to remain the same while the Flask redirect occurs. Is there an option within Flask to do this? Or can I configure the web server to accomplish this? </p>
  
  <p><strong>UPDATE and further details:</strong></p>
  
  <p>I cannot get the nginx proxying to work correctly. My current situation:</p>
  
  <p><a href="http://www.snowpacktracker.com" rel="nofollow noreferrer">www.snowpacktracker.com</a> is setup as a custom domain (using a Heroku-provided DNS target) for my Heroku app that is running nginx + gunicorn + Flask (this is a working link you can use to see the current behavior). The underlying URL for this Heroku app is <a href="https://snowpacktracker.herokuapp.com" rel="nofollow noreferrer">https://snowpacktracker.herokuapp.com</a>.</p>
  
  <p>When this first Heroku app receives a request, the Flask app redirects to a second Heroku app running a Bokeh server. As currently implemented, you can see the URL switch in the browser to <a href="https://invlabs-bokehserver.herokuapp.com/avyview?style=snowpacktracker" rel="nofollow noreferrer">https://invlabs-bokehserver.herokuapp.com/avyview?style=snowpacktracker</a>. </p>
  
  <p>Both <a href="http://www.snowpacktracker.com" rel="nofollow noreferrer">www.snowpacktracker.com</a> and <a href="http://www.snowpacktracker.com/btac" rel="nofollow noreferrer">www.snowpacktracker.com/btac</a> redirect to the same URL. I have a second style defined with <a href="http://www.snowpacktracker.com/btac/historic" rel="nofollow noreferrer">www.snowpacktracker.com/btac/historic</a> that redirects to <a href="https://invlabs-bokehserver.herokuapp.com/avyview" rel="nofollow noreferrer">https://invlabs-bokehserver.herokuapp.com/avyview</a>.</p>
  
  <p><strong>My goal is for a page load of <a href="http://www.snowpacktracker.com" rel="nofollow noreferrer">www.snowpacktracker.com</a> (and any extensions: /btac or /btac/historic) to redirect via Flask as is currently implemented, but for the original URL to remain unchanged.</strong></p>
  
  <p>I have been trying to edit the <code>location</code> block in the <code>nginx.conf.erb</code> config file according to the link in the answer from @Fian, but I am having no luck.</p>
  
  <p>What are the correct statements for <code>proxy_pass</code> or <code>proxy_redirect</code> (or <code>rewrite</code>?) in the <code>location</code> block to accomplish this desired behavior?</p>
  
  <p>My current nginx config file (provided in the <a href="https://github.com/ryandotsmith/nginx-buildpack/blob/master/config/nginx.conf.erb" rel="nofollow noreferrer">Heroku nginx build pack</a>):</p>
  
  <pre><code>daemon off;
  #Heroku dynos have at least 4 cores.
  worker_processes &lt;%= ENV['NGINX_WORKERS'] || 4 %&gt;;
  
  events {
      use epoll;
      accept_mutex on;
      worker_connections 1024;
  }
  
  http {
          gzip on;
          gzip_comp_level 2;
          gzip_min_length 512;
  
      server_tokens off;
  
      log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
      access_log logs/nginx/access.log l2met;
      error_log logs/nginx/error.log;
  
      include mime.types;
      default_type application/octet-stream;
      sendfile on;
  
      #Must read the body in 5 seconds.
      client_body_timeout 5;
  
      upstream app_server {
          server unix:/tmp/nginx.socket fail_timeout=0;
      }
  
      server {
          listen &lt;%= ENV["PORT"] %&gt;;
          server_name _;
          keepalive_timeout 5;
  
          location / {
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_redirect off;
              proxy_pass http://app_server;
          }
      }
  }
  </code></pre>