Modern versions of Apache and Redirect

November 6, 2010

Our main web server is currently running Ubuntu 8.04. For reasons beyond the scope of this entry, we want to upgrade it to Ubuntu 10.04, so today I did a test install, which wound up exploding with a bunch of log messages that looked like:

[...] .htaccess: Redirect: invalid first argument (of three)

Internet searches will give you inconclusive and somewhat confused answers; it doesn't help that Apache doesn't report a line number, and that Redirect can validly take three arguments.

What you have probably done is written a Redirect that looks like this:

Redirect /a/path http://some.where/ [L]

This is a superstition. Redirect doesn't take a flags argument at the end; only RewriteRule does. It used to be harmless to put flags on the end anyways, so people did it for various reasons (mistaken belief that it was required, laziness, forgetfulness, etc). Modern versions of Apache are more picky about Redirect directives and so choke on this with the error message you see here.

(This error is especially fun in a .htaccess, because if there are any problems with a .htaccess Apache locks you out of the directory it's in. As it happened, some of our crucial .htaccess files had this problem.)

Sidebar: the Apache versions involved

To save you looking this up: Ubuntu 10.04 has Apache 2.2.16 and Ubuntu 8.04 has Apache 2.2.8. The pickiness was apparently introduced in this change in July of 2009, and it appears that this then appeared in 2.2.12 (per the CHANGES_2.2 file, which lists this PR as one of the 2.2.12 changes). Before the change, Apache would just ignore the third argument of a three-argument Redirect if it couldn't interpret the first argument as a redirection status. After the change, it considers it an error.

Looking at the change, it's hard to criticize the Apache people for it; the previous behavior was a great way to have mistakes compound themselves.


Comments on this page:

By Bhavin at 2017-12-19 13:47:47:

This entry was very helpful in understanding a similar issue that I am having.

Written on 06 November 2010.
« GNU sort and -k: a gotcha
When you should care about security »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Nov 6 01:06:41 2010
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.