如何使用 apache 提供脚本而不是运行它?
我正在尝试使用 apache Web 服务器托管 python 脚本,但服务器尝试运行该脚本,而不是仅仅提供下载。
我无法直接访问服务器,并且将行添加
AddType text/plain .py
到根文件夹中的 .htaccess 似乎不起作用,尽管我可能做错了什么。
如何让服务器仅将文件作为文本发送而不是尝试运行它?
-编辑
更改名称不起作用。 当您单击 Script.py.safe 时,它仍然会给出 500 服务器错误。
我还应该提到 .htaccess 文件确实有效,但由于某种原因,一个 addType 行不起作用。 要么是因为它没有覆盖某些东西,要么是线路错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在您的 .htaccess 中:
In your .htaccess:
如果您无法更改 Apache 配置并且无法使用 htaccess 文件覆盖它,那么在我看来,最简单的解决方案是更改文件扩展名,或者编写一个打印以下内容的脚本目标脚本。
两者在某种程度上都是 hack,但正确的解决方案是更改 Apache 配置。
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.
一种选择是更改扩展名并明确应重命名。 IE python.py.safe 或 python.py.dl。 然后用户需要删除额外的位。
你也可以把它拉上拉链。
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.
在文件夹的 .htaccess 中应该可以工作;)
in a .htaccess for the folder should work ;)
我会写一些加载 python 脚本的东西。 这样,您甚至可以变得精力充沛,并包括代码的格式和样式。 你甚至可以用 python 编写它,因为你不会通过文件扩展名来排除它。
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.