Apache 2.2 URL Rewriting Guide From Static to Dynamic 404 Not Found script not found or unable to stat: redirect:/

Apache users:

I'm trying to learn how to use the Apache rewrite module to redirect
incoming hits for virtual *.html pages to Perl CGI scripts using the
information provided in the Apache 2.2 manual "URL Rewriting Guide"
chapter "From Static to Dynamic" section:

<a href="" title=""></a>

For my first test, I am attempting to have hits for the page:

<a href="" title=""></a>

invoke the script at URL:

<a href="" title=""></a>

which resides in file:


When I invoke the script via its direct URL, everything works:

<a href="" title=""></a>

But when I request the URL that is supposed to be rewritten:

<a href="" title=""></a>

I see:

404 Not Found

and the Apache error log says:

script not found or unable to stat: redirect:/

Also, I have attempted to enable the rewrite log and set the target
directory mode to 0777, but no log file is written (?).

Please see console session, below.

Any suggestions?



2011-02-19 22:18:15 dpchrist@p43400e ~/bluefish
$ cat /etc/debian_version

2011-02-19 21:18:20 dpchrist@p43400e ~/bluefish
$ sudo apache2ctl -V
Server version: Apache/2.2.16 (Debian)
Server built: Jan 1 2011 21:57:31
Server's Module Magic Number: 20051115:24
Server loaded: APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture: 32-bit
Server MPM: Worker
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/worker"
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"

2011-02-19 21:18:23 dpchrist@p43400e ~/bluefish
$ cat /etc/apache2/apache2.conf | grep '.' | egrep -v '^#'
LockFile ${APACHE_LOCK_DIR}/accept.lock
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
<IfModule mpm_event_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestsPerChild 0
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
DefaultType text/plain
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include mods-enabled/*.load
Include mods-enabled/*.conf
Include httpd.conf
Include ports.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\"
\"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Include conf.d/
Include sites-enabled/

2011-02-19 21:25:14 dpchrist@p43400e ~/bluefish
$ l -w 64 /etc/apache2/mods-enabled/
./ autoindex.conf@ mime.load@
../ autoindex.load@ negotiation.conf@
alias.conf@ cgid.conf@ negotiation.load@
alias.load@ cgid.load@ reqtimeout.conf@
auth_basic.load@ deflate.conf@ reqtimeout.load@
authn_file.load@ deflate.load@ rewrite.load@
authz_default.load@ dir.conf@ setenvif.conf@
authz_groupfile.load@ dir.load@ setenvif.load@
authz_host.load@ env.load@ status.conf@
authz_user.load@ mime.conf@ status.load@

2011-02-19 21:54:51 dpchrist@p43400e ~/bluefish
$ cat /etc/apache2/sites-enabled/
# $Id:,v 1.5 2011-02-20 05:54:48 dpchrist Exp $
<VirtualHost *:80>
DocumentRoot /home/dpchrist/bluefish/public_html
RewriteLog /home/dpchrist/bluefish/log/rewrite.log
ScriptAlias /cgi-bin/ /home/dpchrist/bluefish/cgi-bin/

2011-02-19 21:54:59 dpchrist@p43400e ~/bluefish
$ sudo apache2ctl configtest
Syntax OK

2011-02-19 21:55:05 dpchrist@p43400e ~/bluefish
$ sudo apache2ctl graceful

2011-02-19 21:55:46 dpchrist@p43400e ~/bluefish
$ l -w 64 public_html/
./ .htaccess favicon.png madewithbluefish-w3cstyle1.png
../ CVS/ index.html

2011-02-19 21:57:14 dpchrist@p43400e ~/bluefish
$ cat public_html/.htaccess
# $Id: .htaccess,v 1.2 2011-02-20 05:47:55 dpchrist Exp $
Options +ExecCGI
AddHandler cgi-script pl
RewriteEngine on
RewriteBase /
RewriteRule ^printenv\.html$ [H=cgi-script]

2011-02-19 21:59:48 dpchrist@p43400e ~/bluefish
$ cat public_html/
#! /usr/bin/perl
# $Id:,v 1.3 2011-02-20 05:47:55 dpchrist Exp $
print "Content-Type: text/plain\n\n";
foreach my $k (sort keys %ENV) {
print $k, ' ', $ENV{$k}, "\n";

2011-02-19 22:00:41 dpchrist@p43400e ~/bluefish
$ wget -O - <a href="" title=""></a>
--2011-02-19 22:01:00-- <a href="" title=""></a>
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: `STDOUT'

[<=> ] 0 --.-K/s
DOCUMENT_ROOT /home/dpchrist/bluefish/public_html
HTTP_USER_AGENT Wget/1.12 (linux-gnu)
SCRIPT_FILENAME /home/dpchrist/bluefish/public_html/
SERVER_ADMIN [no address given]
SERVER_SIGNATURE <address>Apache/2.2.16 (Debian) Server at Port 80</address>

SERVER_SOFTWARE Apache/2.2.16 (Debian)
TZ America/Los_Angeles
[ <=> ] 765 --.-K/s in

2011-02-19 22:01:00 (61.2 MB/s) - written to stdout [765]

2011-02-19 22:01:00 dpchrist@p43400e ~/bluefish
$ wget -O - <a href="" title=""></a>
--2011-02-19 22:01:14-- <a href="" title=""></a>
Connecting to||:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2011-02-19 22:01:14 ERROR 404: Not Found.

2011-02-19 22:01:14 dpchrist@p43400e ~/bluefish
$ sudo tail -n 3 /var/log/apache2/error.log
[Sat Feb 19 22:00:41 2011] [notice] SIGUSR1 received. Doing graceful
[Sat Feb 19 22:00:41 2011] [notice] Apache/2.2.16 (Debian) configured --
resuming normal operations
[Sat Feb 19 22:01:14 2011] [error] [client] script not
found or unable to stat: redirect:/

2011-02-19 22:31:26 dpchrist@p43400e ~/bluefish
$ ll -d ~/.
drwxr-xr-x 53 dpchrist dpchrist 4096 Feb 19 21:54 /home/dpchrist/./

2011-02-19 22:34:37 dpchrist@p43400e ~/bluefish
$ ll -d ~/bluefish/
drwxr-xr-x 7 dpchrist dpchrist 4096 Feb 19 22:25 /home/dpchrist/bluefish//

2011-02-19 22:34:44 dpchrist@p43400e ~/bluefish
$ ll -d ~/bluefish/log
drwxrwxrwx 3 dpchrist dpchrist 4096 Feb 19 22:31

2011-02-19 22:34:47 dpchrist@p43400e ~/bluefish
$ l log/
./ ../ .cvsignore .exists CVS/


Re: Apache 2.2 URL Rewriting Guide From Static to

By =?utf-8?Q?Igor_... at 02/20/2011 - 16:37

Why? (<a href="" title=""></a>)

<a href="" title=""></a>

You do not, NEVER EVER chmod something 0777. There is no place for
0777 on any server. Not even a test server. There is a place for
1777 and that place is /tmp and /var/tmp.

Generally, mod_rewrite is debugged using RewriteLog.
<a href="" title=""></a>

But see below.

Aha.. might want to check out:
<a href="" title=""></a>
later on...

How many people, I wonder, have mod_authz_groupfile loaded
without using it?

Why when you have full access to the config do you put your
rewrite rules in .htaccess?

Please their documentation for what they are good for:
<a href="" title=""></a>

Finally, I fail to see why you're even using rewrite for that thing?
You could just name your files .html, make them executable.

Options +ExecCGI would only pick up those that are exectuable.
Of course that's not "transparent" but if you're looking for
transparency, why not just *drop* .html *and* .pl from the *Request*
and have Options +MultiViews take care of serving the right file?

See my last mail to users@ which, too, suggests avoiding mod_rewrite:)
<a href=" ... at httpd dot" title=" ... at httpd dot"> ... at httpd dot</a>


Re: Apache 2.2 URL Rewriting Guide From Static to

By David Christensen at 02/21/2011 - 15:22

Apache users:

I've boiled the example down, attempted to clarify, and re-posted it on
the debian-user mailing list:

<a href="" title=""></a>


Re: Apache 2.2 URL Rewriting Guide From Static to

By David Christensen at 02/20/2011 - 18:20

On 02/20/2011 12:37 PM, Igor Galić wrote:

As a matter of fact, I *do* know how to operate a jackhammer. Do you
need your demons let out? ;-)

Oh, isn't he cute!

I was expecting Apache to run as www-data:

2011-02-20 13:35:44 dpchrist@p43400e ~/bluefish
$ sudo grep -r APACHE_RUN_USER /etc
/etc/apache2/envvars:export APACHE_RUN_USER=www-data
/etc/apache2/apache2.conf:User ${APACHE_RUN_USER}

But, Apache seems to be running as root:

2011-02-20 14:00:57 dpchrist@p43400e ~/bluefish
$ chmod 0755 log

2011-02-20 14:06:11 dpchrist@p43400e ~/bluefish
$ sudo rm log/rewrite.log

2011-02-20 14:06:18 dpchrist@p43400e ~/bluefish
$ sudo apache2ctl graceful

2011-02-20 14:06:25 dpchrist@p43400e ~/bluefish
$ ll log/rewrite.log
-rw-r--r-- 1 root root 0 Feb 20 14:06 log/rewrite.log

So, you're right -- mode 0777 wasn't necessary in this case.

(Perhaps a Debian bug report is in order...)

Unfortunately, it's empty. (Another Debian bug report?)

587,243, give or take. ;-)

Because I don't have full access to the config file on shared hosting

Yes, I've read that: past, present, and future. :-)

So, if I want HTML pages to be generated by Perl scripts named *.html,
then should I write HTML pages named *.pl to generate my Perl scripts?
Do I then pipe the output of wget to perl -e? But, how do I feed that
into Apache to generate the HTML page? Perhaps I should really use
*.html for Bash scripts? ;-)

<a href="" title=""></a>

<a href="" title=""></a>

<a href="" title=""></a>


<a href="" title=""></a>

"These examples assume the RewriteRules are not placed in a directory
context (i.e., not in a .htaccess file nor in a <Directory> section)."

For this test, the rewrite rules are in .htaccess.

<a href="" title=""></a>

"The most common situation in which mod_rewrite is the right tool is
when the very best solution requires access to the server configuration
files, and you don't have that access. Some configuration directives are
only available in the server configuration file. So if you are in a
hosting situation where you only have .htaccess files to work with, you
may need to resort to mod_rewrite."

Shared hosting without access to the server configuration files is the
use-case I am testing.