Ratings, reviews, plans and features to help you find the right web hosting provider for your site.

Enable CGI, SSI with .htaccess

Web Hosting Articles » A simple guide to .htaccess » Enable CGI, SSI with .htaccess



As .htaccess is a powerful tool. It gives you option to change the way the webserver serves your files. On most web hosting servers you can use SSI (Server Side Includes) in shtml, or shtm files.

However, you need to use SSI in your .html and htm files. There is an easy solution for this.
Just add the following line in your .htaccess file:

AddHandler server-parsed .html .htm

This line will tell the server to parse your .htm file as SSI and execute any SSI directives you have there.

You can also use .htaccess to enable CGI scripts execution as well as change the default extension for such files as well.

For Perl/CGI scripts you will need:

AddHandler cgi-script .cgi .pl

To make PHP files to be parsed as PHP when PHP is running as module

AddType application/x-httpd-php .html .htm


To make PHP files to be parsed as PHP when PHP is running as CGI (suexec, etc)

AddHandler application/x-httpd-php .html .htm

  1. How to block users from accessing your site based on their IP address
  2. How to prevent or allow directory listing?
  3. How to change the error documents – 404 Page Not Found, etc
  4. Using .htaccess for password protecting your folders
  5. Using .htaccess to block referrer spam
  6. Disable Hot-Linking of images and other files
  7. Redirect URLs using .htaccess
  8. Introduction to mod_rewrite and some basic examples
  9. Force SSL/https using .htaccess and mod_rewrite
  10. 301 Permanent redirects for parked domain names
  11. Enable CGI, SSI with .htaccess
  12. How to add Mime-Types using .htaccess
  13. Change default directory page
  14. Block Bad robots, spiders, crawlers and harvesters
  15. Make PHP to work in your HTML files with .htacess
  16. Change PHP variables using .htaccess
  17. HTTP Authentication with PHP running as CGI/SuExec
  18. Force www vs non-www to avoid duplicate content on Google
  19. Duplicate content fix index.html vs / (slash only)

Comments 5 >>

Rob Shaffer Said,
Oct 09, 2007 @ 13:06

We needed to add the following as well :


AddHandler extension_Type .html .htm .php3 .php4
Action Extension_Type /cgi-bin/php.dat
meeero Said,
Oct 29, 2007 @ 16:15

sure? my apache says "Invalid command 'Action'"
randy s Said,
Apr 11, 2008 @ 09:45

AddHandler extension_Type .html .htm .php3 .php4
Action Extension_Type /cgi-bin/php.dat

This works correctly on our Network Solutions Unix package. PHP is running as CGI with path as show to the dat file.

Thank you!
S P Arif Sahari Wibowo Said,
Nov 21, 2008 @ 11:04

Just addhandler may not enough to allow CGI run. From Apache manual (http://httpd.apache.org/docs/2.2/howto/htaccess.html), you need both comman below:

Options +ExecCGI
AddHandler cgi-script cgi pl
Calling Cards Said,
Jan 13, 2009 @ 12:06

Each server is different..I had them combined until it work.
Your comments on this article

(required)

(required but never displayed)



security code



Previous: 301 Permanent redirects for parked domain names Next: How to add Mime-Types using .htaccess