Tuesday, February 8, 2011

How do I serve a script with apache instead of running it?

I'm trying to host a python script using an apache web server, but the server tries to run the script instead of just offering it for download.

I do not have direct access to server, and adding the line

AddType text/plain .py

to .htaccess in the root folder does not appear to work, though I could be doing something wrong.

How do I get the server to just send the file as text instead of trying to run it?

-Edit

Changing the name does not work. Script.py.safe still give a 500 Server error when you click it.

I should also mention that the .htaccess file does work, but for some reason that one addType line is not working. Either because it's not overriding something, or the line is wrong.

  • If you can't change the Apache config and you can't override it with an htaccess file, then it seems to me that the easiest solutions would be either to change the file extension, or else to write a script that prints the contents of the target script.

    Both are hacks to some extent, but the correct solution is to change the Apache config.

    From jbourque
  • One option is to change the extention and make clear that it should be renamed. IE python.py.safe or python.py.dl. The user would then need to remove the extra bit.

    You could also Zip it up.

    From Tilendor
  • I would write something that loads the python script up. This way you could even get energetic and include formatting and styling of the code. You could even write it in python since you will not have precluded that by file extension.

    Grant : I was hoping for more of a 1 minute solution vs. a 1 day solution. ;)
  • <IfModule mime_module>
        <Files *.py>
            ForceType text/plain
        </Files>
    </IfModule>
    

    in a .htaccess for the folder should work ;)

    From Mez
  • In your .htaccess:

    RemoveHandler .py

    From djsadinoff

0 comments:

Post a Comment