Search code examples
pythonhtmlscriptingcgi-bin

Running a Python Script on a server (Does it have to be in /cgi-bin/)?


Right now I have a script thats

http://www.example.com/cgi-bin/foo?var1=A&var2=B

Is there a way that I can have it run outside of the cgi-bin directory? Like could I have

http://www.example.com/foo/?var1=A&var2=B

Solution

  • In Apache you can change the directories that can contain executable scripts with the ScriptAlias directive in httpd.conf (or whatever file holds your configuration).

    You can also use mod_rewrite to rewrite URLs to point to the scripts you want to execute. Mod_rewrite also allows you to pass variables and stuff in the form of URLs if you like that, e.g.

    www.example.com/foo/A/B/ -> www.example.com/foo?var1=A&var2=B