[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Apache rewrite module From Static to Dynamic



debian-user:

I have a Debian 6.0.0 (Squeeze) computer with the "apache" Debian package installed:

$ cat /etc/debian_version
6.0

$ sudo apache2ctl -v
Server version: Apache/2.2.16 (Debian)
Server built:   Jan  1 2011 21:57:31


I am trying to learn about the Apache rewrite module via "Apache HTTP Server Version 2.2 Documentation" "URL Rewriting Guide" "useful examples" "From Static to Dynamic":

http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#static-to-dynamic


I have enabled the Rewrite module:

$ ll /etc/apache2/mods-enabled/rewrite.load
lrwxrwxrwx 1 root root 30 Feb 19 20:00 /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load


I have created a virtual host and some files for testing:

$ cat /etc/apache2/sites-enabled/apache-sandbox-p43400e.holgerdanske.com
<VirtualHost *:80>
    ServerName   apache-sandbox-p43400e.holgerdanske.com
    DocumentRoot           /home/dpchrist/apache-sandbox/public_html
    RewriteLog             /home/dpchrist/apache-sandbox/log/rewrite.log
    ScriptAlias  /cgi-bin/ /home/dpchrist/apache-sandbox/cgi-bin/
</VirtualHost>

$ cat apache-sandbox/public_html/rewrite/.htaccess
Options +ExecCGI
AddHandler cgi-script pl
RewriteEngine  on
RewriteBase    /rewrite/
RewriteRule    ^rewrite\.html$  rewrite.pl  [H=cgi-script]

$ cat apache-sandbox/public_html/rewrite/index.html
<html>
  <body>
    Apache 2.2 Rewrite demonstration
    <ul>
      <li>CGI script <a href="rewrite.pl">rewrite.pl</a></li>
      <li>Virtual HTML page <a href="rewrite.html">rewrite.html</a></li>
    </ul>
  </body>
</html>

$ cat apache-sandbox/public_html/rewrite/rewrite.pl
#! /usr/bin/perl
print "Content-Type: text/plain\n\n";
print "whoami: ", `whoami`, "\n";


When I browse the web page and CGI script, all is well:

$ wget -q -O - http://apache-sandbox-p43400e.holgerdanske.com/rewrite/
<html>
  <body>
    Apache 2.2 Rewrite demonstration
    <ul>
      <li>CGI script <a href="rewrite.pl">rewrite.pl</a></li>
      <li>Virtual HTML page <a href="rewrite.html">rewrite.html</a></li>
    </ul>
  </body>
</html>

$ wget -q -O - http://apache-sandbox-p43400e.holgerdanske.com/rewrite/rewrite.pl
whoami: www-data


But when I try to use the Rewrite feature, I see two problems:

1. When I try to browse the virtual HTML page, Apache can't find the script:

$ sudo apache2ctl graceful; sudo rm apache-sandbox/log/rewrite.log

$ wget -S -q -O - http://apache-sandbox-p43400e.holgerdanske.com/rewrite/rewrite.html
  HTTP/1.1 404 Not Found
  Date: Mon, 21 Feb 2011 05:58:22 GMT
  Server: Apache/2.2.16 (Debian)
  Vary: Accept-Encoding
  Content-Length: 323
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1

$ sudo tail -n 3 /var/log/apache2/error.log
[Sun Feb 20 21:57:27 2011] [notice] SIGUSR1 received. Doing graceful restart [Sun Feb 20 21:57:27 2011] [notice] Apache/2.2.16 (Debian) configured -- resuming normal operations [Sun Feb 20 21:58:22 2011] [error] [client 192.168.0.34] script not found or unable to stat: redirect:/rewrite/rewrite.pl


2.  The rewrite log is empty and owned by root:

$ ll apache-sandbox/log/rewrite.log -rw-r--r-- 1 root root 0 Feb 20 21:57 apache-sandbox/log/rewrite.log


Any suggestions?


TIA,

David


Reply to: