1

I have a problem similar to this question - I'm restricted to using 1and1 hosting, running cgi through virtualenv.

I have the following in my .htaccess file:

Options +ExecCGI

DirectoryIndex index.cgi

RewriteEngine On
RewriteRule ^/mypath/test/index.cgi/(.*)$ - [S=1]
RewriteRule ^/mypath/test/(.*)$ /mypath/test/index.cgi/$1 [QSA,L]

My index.cgi contains

#!/path/to/myenv/bin/python

from wsgiref.handlers import CGIHandler
from flask import Flask

app = Flask(__name__)

@app.route("/", defaults={"path":''})
@app.route("/<path:path>")
def main(path):
    return "oh hai, mr. %s" % path


@app.route("/fnord")
def fnord():
    return "allo"

CGIHandler().run(app)

What I would like to be able to do is go to www.mysite.com/mypath/test/page-one and www.mysite.com/mypath/test/page-two. But right now all I can do is go to index.cgi or index.cgi/fnord. I can also go to /test/. What do I need to do to fix this?

1 Answer 1

2

Try removing the leading slashes in your rule's patterns:

RewriteRule ^mypath/test/index.cgi/(.*)$ - [S=1]
RewriteRule ^mypath/test/(.*)$ /mypath/test/index.cgi/$1 [QSA,L]

The URI has the leading slash stripped off when applying rules inside an htaccess file.

You can also replace the [S=1] with simply [L].

Sign up to request clarification or add additional context in comments.

1 Comment

Ahah - this worked + placing the .htaccess file in the root folder of the webpage, i.e. mv .htaccess ~/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.