What Are Apache Handlers and How to Configure Them Print

  • apache handlers, cgi scripts, file extensions, server configuration, htaccess, apache configuration, web server, control panel
  • 0

Apache handlers control how your web server processes specific file types and extensions. By configuring handlers, you can tell Apache to execute CGI scripts, parse server-side includes, or process other special file types instead of serving them as plain text. This allows you to customize how your website handles different files without changing the underlying server configuration.

What Apache Handlers Do

Apache handlers define how the web server software manages certain file types and file extensions. When Apache receives a request for a file, it checks the file extension and uses the corresponding handler to process it. Common file extensions that use handlers include .cgi, .pl, .plx, .ppl, .perl, and .shtml.

You can configure Apache to use an existing handler for new file types by manually adding the handler and extension through your hosting control panel. This gives you flexibility to customize how your server processes different files without needing direct server access.

Built-In Apache Handler Types

Apache includes several pre-configured handlers that serve different purposes:

  • default-handler - Sends the file using Apache's default method for static content like HTML and images
  • send-as-is - Sends the file with HTTP headers unchanged, useful for files that already contain proper headers
  • cgi-script - Executes the file as a CGI script, commonly used for Perl scripts and other executable programs
  • server-parsed - Parses the file for server-side includes (SSI), allowing dynamic content insertion
  • imap-file - Parses the file as an imagemap rule file for clickable image regions
  • server-info - Retrieves the server's configuration information (typically restricted)
  • server-status - Retrieves the server's status report showing current connections and activity
  • type-map - Parses the file as a type map for content negotiation

How to Create an Apache Handler

Adding a custom Apache handler through your OBHost control panel is straightforward. Follow these steps:

  1. Navigate to the Apache Handlers section in your control panel
  2. Enter the handler name in the Handler field (choose from the built-in handlers listed above or specify a custom handler)
  3. Enter the file extension in the Extension(s) field
  4. Click the Add button to activate the handler

Understanding File Extensions

A file extension consists of the characters after the dot in a filename (for example, filename.html where "html" is the extension). When entering extensions, you can specify multiple extensions for the same handler by separating them with spaces (for example, "cgi pl plx").

Common Handler Use Cases

Here are practical examples of when you might configure Apache handlers:

  • Making .pl files execute as CGI scripts instead of displaying source code
  • Enabling server-side includes for .shtml or .html files
  • Processing custom file extensions with specific handlers
  • Controlling how the server responds to special file types

Managing Existing Handlers

Once you create handlers, you can view them in your control panel's Apache Handlers interface. Each handler displays the handler name and associated file extensions. You can delete handlers you no longer need by clicking the delete icon next to the handler entry. Deleting a handler reverts the file extensions to their default behavior.

Handler Configuration and .htaccess Files

When you add handlers through the control panel, Apache stores this configuration in your website's .htaccess file. Advanced users can also manually edit .htaccess to add handler directives using the AddHandler syntax. However, using the control panel interface is safer and prevents syntax errors that could break your website.

Frequently Asked Questions

What happens if I assign the wrong handler to a file extension?

If you assign an incorrect handler, files with that extension may not work properly. For example, if you assign the cgi-script handler to .html files, Apache will try to execute your HTML pages as scripts, which will cause errors. You can fix this by deleting the incorrect handler or changing it to the appropriate one.

Can I use Apache handlers for custom file extensions?

Yes, you can associate any file extension with an Apache handler. This is useful when you want files with custom extensions (like .myext) to be processed in a specific way. Just enter your custom extension and select the appropriate handler based on how you want those files processed.

Why aren't my CGI scripts executing after adding a handler?

If CGI scripts don't execute after adding a handler, check that the files have the correct permissions (typically 755). Also verify that the script includes the proper shebang line at the top (like #!/usr/bin/perl) and that CGI execution is enabled for the directory. OBHost servers support CGI execution, but file permissions must be set correctly.

Do Apache handler changes take effect immediately?

Yes, handler changes take effect immediately after you save them. You don't need to restart the web server. If changes don't appear to work, clear your browser cache or try accessing the file in a private browsing window to ensure you're not seeing cached content.

Our support team is available 24/7 to help you configure Apache handlers or troubleshoot any server configuration issues. Contact us at https://www.obhost.net/contact or email support@obhost.org for assistance.


Was this answer helpful?

« Back