VolkerK makes a good point: don't use both RewriteEngine on
and RewriteEngine off
, because you're not turning the rewriting engine on, adding a rule, and turning it off again. Apache configuration does not work like programming, where you have a set of instructions that the computer executes in order. You can imagine it more like this: when Apache parses its configuration files (like .htaccess
), it first reads in all the directives and sorts them out into a natural order in which they will be applied. It's more like initializing the values of variables at the start of a program, where the outcome is generally the same regardless of what order you write the statements in.
In your case, specifying both RewriteEngine on
and RewriteEngine off
in the same file is likely to confuse Apache, since (in my little metaphor) when Apache sorts the directives into their "natural" order, it'd wind up with something like
RewriteEngine on
RewriteEngine off
RewriteRule ...
which would presumably turn the rewrite engine off. But of course, what actually happens is more complicated than just sorting directives into a list, so you can't really tell what Apache will do with a file like yours. Just don't try to turn the rewrite engine on and off for different parts of the file, and remember that Apache's configuration directives aren't just statements to be run in order.