Q:

How can I resolve 404 errors caused by CGIRootFix?

I'm deploying Flask on a shared server where I am needing to serve it with CGI. I've been able to remove the filename from the URLs with the following .htaccess code:
AddHandler cgi-script .cgi .pl

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/tetra/public_html/cgi-bin/tetra.cgi/$1 [L]

However, any time I use url_for() to generate a link, it inserts the cgi-bin filepath back into the link, so, https://servername/auth/login becomes https://servername/cgi-bin/app.cgi/auth/login.
When I remove cgi-bin/app.cgi/ from the URL, the URL works fine. In searching this issue I see that CGIRootFix can likely be used to resolve this problem by removing the filepath from the URL:
http://werkzeug.pocoo.org/docs/0.14/contrib/fixers/
I've tried adding this to my CGI file:
from werkzeug.contrib.fixers import CGIRootFix

app = CGIRootFix(app,app_root='/')

Full file:
#!<path redacted>

#path to python packages
import sys
sys.path.insert(0, '<path redacted>')

from wsgiref.handlers import CGIHandler
from myapp import app
from werkzeug.contrib.fixers import CGIRootFix

app = CGIRootFix(app,app_root='/')

if __name__ == '__main__':
  CGIHandler().run(app)

This does resolve the issue with the URLs hat url_for() generated, which I can test from flask shell via the command line:
>>> from flask import url_for
>>> url_for('main.index')
'http://servername/'
>>> url_for('auth.login')
'http://servername/auth/login'

But... visiting the URL now causes a 404 error. None of the pages load using any URL, either the desired URLs or the URLs with the filenames included. It's got to be some dumb configuration problem, but the documentation is a little thin as are the other questions I've found on the issue.
I have also tried app.wsgi_app = CGIRootFix(app.wsgi_app,app_root='/') and a few other variations from the threads I've previously seen.
Any idea what's causing it to 404 when I use CGIRootFix and what I can do to get it to load the page with the desired URLs?

A:

I never figured out how to get this fixer to work, however, I believe it may be because it's an outmoded solution. I was able to fix the links with the following changes in my code:
Adding app.config['_external']=True to the config, and then in the .cgi file adding os.environ['SCRIPT_NAME']="" right before the app execution line. You may be able to add SCRIPT_NAME="" to the config for your site as well and it only works if _external is also set. The end result is that it is not working and my URLs are correct.
Really hoping this helps someone else in the same situation.

