【问题标题】:where to place .htaccess for apache cgi-bin在哪里放置 .htaccess 的 apache cgi-bin
【发布时间】:2015-05-11 07:12:24
【问题描述】:

我在 /usr/lib/cgi-bin/ 文件夹下有一个 python 脚本。
此脚本可从 URL 访问:http://localhost/cgi-bin/test.py
现在我想在 .htaccess 文件中使用 SetEnv 设置一个 Apache 环境变量。 .htaccess 文件必须放在哪里,以便我可以在我的 python 脚本中访问 env 变量?

感谢 F481

【问题讨论】:

  • 你试过把它放在cgi-bin吗?
  • 是的,但没有成功。

标签: apache .htaccess apache2 cgi cgi-bin


【解决方案1】:

正如他们所写的here、htaccess works in all directories except cgi-bin。但是,正如您在 here 中看到的那样,有一种解决方法。

基本上,您编辑 httpd.conf 文件的 <Directory "C:/path/to/cgi-bin"> 部分 - 并将 cgi-bin 中的 .htaccess 文件中的任何内容放在那里。

记得在修改 httpd.conf 后重启你的 apache

还有一个花絮:你的 httpd.conf 中可能已经有一个<Directory "/var/www/cgi-bin">。编辑它 - 有重复的部分会导致白发。

上面的方法对我有用,用于保护 cgi-bin 目录的密码,因为在 cgi-bin 中使用 .htaccess 不起作用。将它插入我的 httpd.conf 文件的 <Directory "C:/path/to/cgi-bin"> 部分确实有效。

它现在说:

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

    AuthType Basic
    AuthName "Scripts"
    AuthUserFile /var/secret/.htpasswrd

    Require valid-user
    Satisfy All
</Directory>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-03
    • 2011-01-07
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多