Search code examples
pythonapache.htaccessmod-python

AddHandler directly in .htaccess


In this solution, I installed and enabled mod_python.

Why doesn't adding this in .htaccess

AddHandler mod_python .py
PythonHandler mod_python.publisher

work?

It works if I add this in a <VirtualHost> configuration, but it doesn't seem to work from a .htaccess. This is a bit a shame, because some people don't have access to modify their <VirtualHost> configuration, and can only modify a .htaccess.

On the other hand, AddHandler php5-script .php seems to be available from .htaccess as detailed here.


Solution

  • As mentioned by @DusanBajic in a comment, adding this solved it:

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

    Then simply adding this in the .htaccess file works:

    AddHandler mod_python .py
    PythonHandler mod_python.publisher
    

    Explanation:

    • 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.