直接在 .htaccess 中添加处理程序

AddHandler directly in .htaccess

中,我安装并启用了 mod_python

为什么不在 .htaccess

中添加这个
AddHandler mod_python .py
PythonHandler mod_python.publisher

工作?

如果我在 <VirtualHost> 配置中添加它,它会起作用,但它似乎不适用于 .htaccess。这有点遗憾,因为有些人没有权限修改他们的 <VirtualHost> 配置,只能修改一个 .htaccess.

另一方面,AddHandler php5-script .php 似乎可以从 .htaccess 获得 detailed here

正如@DusanBajic 在评论中提到的,添加这个解决了它:

<VirtualHost *:80>
  ...
  <Directory />
    AllowOverride All
    Allow from all
  </Directory>
</VirtualHost>

然后只需将其添加到 .htaccess 文件中即可:

AddHandler mod_python .py
PythonHandler mod_python.publisher

解释:

  • AllowOverride All:

    When the server finds an .htaccess file (as specified by AccessFileName), it needs to know which directives declared in that file can override earlier configuration directives.