mod_rewrite not working in top directory but OK in subdirectories
I've used mod_rewrite (sparingly) in a few directories before without problems by putting in a .htaccess file for that directory, and it works there now. But when I try to use it in my top level directory, nothing happens!?!?! But that .htaccess file (top level one) is working fine otherwise. I have Redirect 301's and a variety of other things, but not mod_rewrite on. I'm running Apache 2.0.63 with mod_rewrite and mod_proxy loaded.
As a test case I set up the following 4 files (fileA,html, fileB.html, fileC.html, fileD.html) and put them in a /test directory. Each file contains the corresponding letters (e.g. AAAA, BBBB) so I can positively identify them. In the /test directory, I created a .htaccess file with
Redirect 301 /test/fileA.html http://www.xyz.com/test/fileB.html
RewriteEngine on
RewriteRule ^fileC\.html$ fileD.html
and all works as expected: you can only see fileB.html and fileD.html even when requesting 开发者_开发问答A or C.
I then copied these files to the root html directory and added to the .htaccess there:
Options +FollowSymLinks (this was already there)
Redirect 301 /fileA.html http://www.xyz.com/fileB.html
RewriteEngine on
RewriteRule ^fileC\.html$ fileD.html
There are no other commands about these files in the .htaccess. Now you can see fileB.html and fileD.html but also fileC.html and not fileA.html!!! So mod_rewrite rule is NOT WORKING here and the Redirect IS working.
I've searched on the net in vain for ideas on this one. Anyone have a clue on what I'm doing wrong?
Looks like the problem, at least in my test case, was somehow further down in the .htaccess file I did have RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner followed by some RewriteRules that I actually wanted and a RewriteEngine off -- the last being my misguided (?) efforts to clear the RewriteCond so as not to affect possible future RewriteRules. Also I see I originally had a problem with some of them in that I was including the initial "/" in the pattern match, which is apparently incorrect.
I commented all that out and my test case and what I really wanted, started working as expected. Playing around since then makes me believe that RewriteEngine off was the real culprit. Anyhow all is working as expected now. Thanks for pushing me in the right directions and hopefully this helps someone else.
精彩评论