Summary: I'm testing a simple catch-all rewrite rule. It doesn't seem to be taking effect, it's not being logged and I'm not getting any errors.

I'm a junior server administrator trying to gain a better understanding of how to configure the Apache web server. Right now I'm reading through some documentation and experimenting with Apache/2.2.22 on Ubuntu 12.04.5 LTS (Precise Pangolin).

One piece of advice I've read is that it's a good policy to use mod_rewrite to explicitly require HTTP/1.1 and reject HTTP/1.0 requests. The example code given is the following:

RewriteEngine On
RewriteCond %{THE_REQUEST} !HTTP/1\.1$
RewriteRule .* - [F]

I tried adding this block to my configuration file:


I also checked to make sure that mod_rewrite was enabled and that there were no other conflicting rewrite rules, e.g.:

$ sudo a2enmod rewrite

>   Module rewrite already enabled

$ grep -Firl 'Rewrite' /etc/apache2/

>   /etc/apache2/conf.d/security
>   /etc/apache2/mods-enabled/rewrite.load
>   /etc/apache2/mods-available/rewrite.load

Then I restarted Apache and tested out the new configuration with curl:

curl --http1.0

Unfortunately I got back the default welcome page instead of the expected 403 FORBIDDEN response. After a little bit of tinkering I ended up with the following rewrite configuration (in /etc/apache2/conf.d/security):

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3
RewriteCond %{THE_REQUEST} ^.*$
RewriteRule ^.*$ - [F]

Again I get the Apache default welcome page rather than the expected 403 FORBIDDEN response. Here is an example session where I test the server with curl and then check the log files (rewrite, error and access logs):

$ sudo service apache2 restart

>   * Restarting web server apache2
>   ... waiting .                           [OK ]

$ curl

>   <html><body><h1>It works!</h1>
>   <p>This is the default web page for this server.</p>
>   <p>The web server software is running but no content has been added, yet.</p>
>   </body></html>

$ sudo tail -1 /var/log/apache2/rewrite.log


$ sudo tail -2 /var/log/apache2/error.log

>   [Sun Oct 25 18:13:13 2015] [notice] caught SIGTERM, shutting down
>   [Sun Oct 25 18:13:13 2015] [notice] Apache/2.2.22 (Ubuntu) configured -- resuming normal operations

$ sudo tail -1 /var/log/apache2/access.log

> - - [25/Oct/2015:18:13:16 +0000] "GET / HTTP/1.1" 200 402 "-" "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/ libidn/1.23 librtmp/2.3"

What gives?

1 Answer 1


I received an answer from Eric Covener at the Apache httpd mailing list ([email protected]), who informed me that rewrite rules are not inherited by virtual hosts.

The Ubuntu Apache installation comes pre-configured with a catch-all default virtual-host which was not inheriting the rewrite settings. Copy-pasting the identical configuration settings into the virtual-host body resulted in the expected behavior.

After consulting the documentation again (armed with this new insight) I noticed the following section on virtual-hosts in the mod_rewrite references:

In order to have a given virtual-host inherit rewrite rules the following directives are required in the body of that virtual-host configuration block:

RewriteEngine On
RewriteOptions Inherit
  • Can you set your answer as valid ? thanks
    – Froggiz
    Dec 15, 2015 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .