Sending Scripts as Text on the CS Web Server

Revision as of 15:28, 11 November 2026 by Pip (talk | contribs) (Created page with "By default, the web server will treat files that look like scripts as CGI programs and will try to run them on the server. This page describes how to override that behavior a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

By default, the web server will treat files that look like scripts as CGI programs and will try to run them on the server. This page describes how to override that behavior and simply send the files to the client browser as text.

File Extensions Treated as CGI

The file extensions the web server treats as CGI programs are:

  • .cgi
  • .fcg (Run as a FastCGI program)
  • .fcgi (Run as a FastCGI program)
  • .fpl (Run as a FastCGI program)
  • .php (Run as a PHP program)
  • .pl
  • .py

Change Handling of Every File With a Particular Extension

You can change the handling of every file with a given extension in a particular directory. This will also apply the change the subdirectories of that directory.

In the directory where you want to effect the change, edit or create a file named .htaccess . (Note that there's a dot at the beginning of the file name.)

Add to that file the following, adjusted to the extension you want to change (we'll use .py as an example):

AddHandler send-asis .py
AddType text/plain .py

Change Handling of Specific Files

If you have a specific set of files you want to send as text, but there are others (in the same directory or in subdirectories) with the same extension that still need to be treated as CGI, use the directions in this section.

In the directory where you want to effect the change, edit or create a file named .htaccess . (Note that there's a dot at the beginning of the file name.)

Broadly, you want to set the parameters for a specific file using Apache's Files directive:

<Files "filename">
    SetHandler send-asis
    ForceType text/plain
</Files>

You will need to do that separately for each file you want to send as text.

You can also use the wildcards ? and *. The question mark (?) matches any single character. The asterisk (*) matches any contiguous set of characters (including no characters at all).

For example, if all of your filenames started with the text "example" and had a ".py" extension, you could use:

<Files "example*.py">
    SetHandler send-asis
    ForceType text/plain
</Files>

For more complex patterns you can use FilesMatch instead of Files. FilesMatch uses Perl-complatible regular expressions.