Forum Moderators: phranque

Message Too Old, No Replies

Very basic rewriting doesn't seem to do anything

After trying many things, reduced to very basic test

         

catkin

3:34 pm on Nov 10, 2011 (gmt 0)

10+ Year Member



Hello :)

After much experimentation, I have assembled a very basic test of rewriting but it doesn't seem to do anything.

On a Debian Squeeze system, I baselined Apache by:

# aptitude purge apache2 apache2-utils apache2.2-bin apache2.2-common
# rm -fr /etc/apache2 /var/www /var/log/apache2
# aptitude -y install \
apache2 apache2-mpm-prefork \
libapache2-mod-perl2 libapache2-mod-php5 \
libapache2-mod-python libapache2-reload-perl \
nagios3 nagios3-cgi
# a2enmod rewrite

Note: the installation command also restores packages that were removed because they depend on the re-initialised Apache packages.

Created /etc/apache2/conf.d/rewrite_tests:

LogLevel debug
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" \"%e\"" combined

RewriteEngine on
RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 7
RewriteRule ^ - [env=FOO:BAR]
RewriteRule ^/*(.*) http://192.168.3.51/$1 [L,R,NE]


Notes:
  1. The LogFormat re-definition adds envar reporting.
  2. The second RewriteRule is based on the example given in [httpd.apache.org ] in the Canonical Hostnames section, for the port 80 example.
  3. The test server is normally accessed at 192.168.168.51 but is also configured with 192.168.3.51
After restarting Apache:
  1. /var/log/apache2/rewrite.log is created.
  2. Browsing
    http://192.168.168.51
    displays the as-installed index.html but still with
    http://192.168.168.51
    in the URL bar. Then ...
  3. /var/log/apache2/access.log shows "-" in the %e field.
  4. /var/log/apache2/rewrite.log is empty.
  5. /var/log/apache2/error.log shows no errors, only startup messages.
Does the evidence support the theory that rewriting is not doing anything?

Could /etc/apache2/conf.d/rewrite_tests be better devised to test basic rewriting functionality?

Best

Charles

catkin

7:24 pm on Nov 12, 2011 (gmt 0)

10+ Year Member



Solved, thanks to Nominal Animal's post in an Linux Questions thread [linuxquestions.org ] which included: "Because of the way VirtualHosts are configured for Apache on Debian, RewriteRule only works within a Directory directive".

AFAIK he was thinking of the as-installed Debian /etc/apache2/sites-enabled/000-default which is a symlink to /etc/apache2/sites-available/default and contains
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>