With the final cond, I wanted (only wanted it seems) to exclude index files.
Ooh, right, you don't know whether the previously redirected files will be named index.htm when they pass through .htaccess again. It may depend on your server. I should know this, because I have learned from direct personal experience that mine appends the "index.html"-- if there is one-- to directory names at some earlier stage.
You're right. Keep the index.htm why is it better to use rewriterule instead of Redirect 301?
Because g1smd says so. Want to make something out of it? :)
Apache themselves have a list of times when you would
not use mod_rewrite
:: shuffling papers ::
[
httpd.apache.org...]
They list four situations, but the other three only apply at levels above .htaccess. So the one you can fight about is whether to say Redirect(Match) or do it all via mod_rewrite.
When a request moves through htaccess, it hits each module separately, no matter what order you've written your .htaccess in. They're done in the reverse order of installation, which is out of your control unless you have your own server. Generally this means reverse alphabetical order.
You can do some simple experiments to make sure. On mine, mod_setenvif runs before mod_rewrite which in turn runs before mod_alias. If you're on a truly antiquated setup, mod_access will probably run last of all-- which is handy, since its functionality has now been incorporated into the core.
You know how you're always being told to put the specific directives before the more general ones? If you use Redirect by that name in addition to Rewrite, you're in mod_alias. Since this normally runs after mod_rewrite, you're then going back to specific directives after you've done the general ones.
Sometimes it can work. I have a cluster of redirects that apply only to files within a particular directory. Unique names, no chance of ambiguity. To reduce chaos, I gave the directory its own htaccess rather than make all other incoming requests plow through rules that will never apply to them. For this htaccess, everything is done with Redirect or RedirectMatch. It saves time, and there aren't any before-or-after issues because the whole htaccess will run separately, after the top-level one.
Or rather: It saves time up until the moment I forget that plain Redirect, unlike Rewrite, does
not use Regular Expressions, and the server flies into a rage looking for files with literal backslashes \ in their names.