【问题标题】:How to serve html files from XAMPP apache server in windows如何在 Windows 中从 XAMPP apache 服务器提供 html 文件
【发布时间】:2014-08-12 16:59:55
【问题描述】:

我有一个 html 文件,它调用 python 脚本来显示来自表单操作标签的一些数据。我想在 Windows 上通过 XAMPP 运行它们。创建名为CGIPython 的子文件夹后,我将文件放入cgi-bin 文件夹中。如果我将 html 文件称为

http://localhost:82/cgi-bin/CGIPython/Test.html

我收到"The website cannot display the page" 错误。即使我尝试了最低限度的.html 文件,我也会得到同样的错误。但是,如果我直接调用我的.py 页面,它可以正常工作。我的httpd.conf 文件中有这一行:

AddHandler cgi-script .cgi .pl .asp .py .html

我还尝试将 html 文件放在 htdocs 文件夹中。

谢谢

【问题讨论】:

  • 为什么不使用SimpleHttpServerCGIHttpServer 来提供文件?
  • 首先尝试在/cgi-bin/中使用test.py,这个脚本必须print所有html(和http header)。您不能将html.php 文件中的python 代码混合使用。

标签: python html apache


【解决方案1】:

首先尝试在/cgi-bin/ 中使用test.py,这个脚本必须print 所有html(使用http header)。您不能将html.php 文件中的python 代码混合使用。

默认情况下,Apache 仅运行 /cgi-bin/ 中的脚本,因此即使 /cgi-bin/CGIPython 也可能需要对 congif 文件进行一些修改。

Apache 使用操作系统 (Windows) 运行 .py.pl,Windows 知道如何处理它 - 它运行 pythonperl。但是 Windows 不知道如何处理 .html - 它是 python、perl 还是其他语言?

最好使用.htaccess 将名称/test.html 转换为/cgi-bin/test.py

RewriteEngine On
RewriteBase /
RewriteRule ^test.html$ cgi-bin/test.py 

或所有文件

RewriteRule ^(.*)\.html$ cgi-bin/$1.py 

【讨论】:

  • 感谢您的澄清。
猜你喜欢
  • 2013-03-25
  • 2015-10-02
  • 2015-09-12
  • 2018-03-10
  • 2018-05-14
  • 2019-10-11
  • 2017-11-05
  • 1970-01-01
  • 2013-09-27
相关资源
最近更新 更多