How do I make other directories act like the main cgi-bin directory?

You may have noticed that the "cgi-bin" directory at the top level of your site is special — if you put normal website files in it, they won't display, and if you put executable script files in it, the server actually runs them instead of displaying their contents.

If you want to make additional directories work this way, you can do so by placing a one-line .htaccess file in the directory. The file should contain this line of text:

SetHandler cgi-script

That treats every file in the directory as a CGI script. (This command is explained in the Apache Web server documentation.)

Can I use AddHandler instead?

You may have seen other people suggesting a line that contains "AddHandler" instead of "SetHandler", like this:

AddHandler cgi-script .cgi

That will also work, because "SetHandler" and "AddHandler" both allow scripts to be run from any directory. "AddHandler" is less secure, though: it allows visitors to view the contents of non-script files in the script directory. That's fine if that's what you want, but if you aren't careful using "AddHandler", you can end up allowing "hackers" to view the contents of files they shouldn't be able to see, such as script configuration files that contain database passwords.

To mimic a standard "cgi-bin" directory, use "SetHandler". Don't use "AddHandler" unless you fully understand why doing so is less secure.