Training, Open Source computer languages

PerlPythonMySQLTclRubyC & C++LuaJavaTomcatPHPhttpdLinux

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Making all your .html files run a Perl script

A RECIPE FOR DYNAMIC WEBSITES WITH PERL

or how to turn all ".html" URLs in a directory into dynamic pages via CGI scripts.

1. Enable Overrides on a directory by directory basis.

You'll want something like the following in your file /etc/httpd/conf/httpd.conf

<Directory "/home/website/htdocs">

# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.

    Options Indexes FollowSymLinks ExecCGI

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit

    AllowOverride All

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

It's the AllowOverride All that's vital here.


2. Ensure that your Apache server supports modi_rewrite

This line must be present (and not commented out) in /etc/http/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

If you have had to change your configuration file at steps 1 or 2, remember to restart Apache so that it re-reads the config file!

3. Turn the RewriteEngine on as appropriate

In a file called .htacceess in the directories you want to forward:

RewriteEngine On
RewriteRule ^(.*)\.html /cgi-bin/summat.cgi?what=$1

4. Provide the script to which you've targeted your pages

#!/usr/bin/perl

print "content-type: text/html\n\n";

print "I done REAL fab<br>";
($name,$value) = ($ENV{QUERY_STRING} =~ /(.*)=(.*)/);
print "You have called up page $value.html";


See also Further httpd configuration

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Perl on the Network
Perl - More CGI Programs and Facilities
Web Application Deployment - Further httpd Configuration
Web site techniques, utility and visibility
resource index - Perl
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho