Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am using Wolf CMS, which is served by PHP.

I want to redirect /index.html to /index.php.

I put the following in .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} ^index.html$ [NC]
  RewriteRule ^index.html$ index.php [R=301,L]

  # Wolf CMS rewriting
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule ^(.*)$ index.php?WOLFPAGE=$1 [L,QSA]
</IfModule>

This works in that index.html is rewritten as index.php, but then index.php is rewritten as index.php?WOLFPAGE=index.html, which should not occur as the WOLFPAGE rule has a condition that it should only apply if the file does not exist, as indicated by the !-f rewrite condition.

index.php does exist, so why is it being rewritten? Why is the condition being violated?

Update - the server version is:

  • Server: Apache/2.2.17 (Unix)
    • mod_ssl/2.2.17
    • OpenSSL/0.9.8e-fips-rhel5
    • mod_bwlimited/1.4
    • mod_perl/2.0.4
    • Perl/v5.8.8
    • X-Powered-By: PHP/5.2.16

Update2 - I have since moved the site from /test to /, and the problem is not occurring any more. Looking at .htaccess above, I had the incorrect rewrite base; hence the server could not find index.php, which matched the conditions for the WOLFPAGE rewrite.

share|improve this question
add comment

3 Answers

If you simply want to perform a redirect, use

Redirect 301 /index.html http://www.example.com/index.php
share|improve this answer
    
Thanks - I agree the redirect is preferential to the rewrite in this case, but replacing the rewrite with a redirect does not stop the subsequent rewrite from taking place (on the Apache server in question), which is the main problem. –  Steve Nov 4 '11 at 9:43
add comment

Try dropping this line entirely:

RewriteCond %{REQUEST_FILENAME} ^index.html$ [NC]

Also, because it is a PCRE, you should escape the dot:

RewriteRule ^index\.html$ index.php [R=301,L]

You could also try not redirecting with R=301:

RewriteRule ^index\.html$ index.php [L]

I tested with the following .htaccess on my server and it worked just fine:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteRule ^index\.html$ index.php [R=301,L]

  # Wolf CMS rewriting
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule ^(.*)$ index.php?WOLFPAGE=$1 [L,QSA]
</IfModule>

Note that even after I removed this htaccess, index.html still redirected to index.php because my browser remembered that it was a permanent redirect. I had to clear cache and restart my browser to remove that effect.

share|improve this answer
    
Thanks. It doesn't matter what format the rewrite is in - they all work fine, initially. The subsequent rewrite should not be occuring, but it does occur with both rewrite rules you have listed above. The essential question is why? Why is this server not following the condition? –  Steve Nov 4 '11 at 9:48
    
@Steve hm, that's odd, as the rules above work on my server. The subsequent rewrite did not occur. Can you edit your question with some server details? (Version numbers, OS, etc) –  Josh Nov 4 '11 at 12:06
    
Thanks; version added above. –  Steve Nov 5 '11 at 15:07
    
I'll try to reproduce using the same version... in the meantime have you cleared cache and restarted your browser? If you remove the rewrite completely does your browser still redirect? ( that indicates the 403 is cached) –  Josh Nov 5 '11 at 20:05
    
when the problem was occuring, the website was in the folder /test for testing purposes. I have now moved it into the public root folder, and the subsequent WOLFPAGE rewrite is not occuring, presumably because the server can see index.php in the root folder, but couldn't see it in the /test folder, perhaps because .htaccess was setup incorrectly. –  Steve Nov 7 '11 at 5:23
show 1 more comment
up vote 1 down vote accepted

I failed to specify that the website was in the folder /test.

If I had of done so, it would of been clear RewriteBase / is incorrect; it should of been RewriteBase /test/.

share|improve this answer
    
Ah ha! That makes perfect sense. Glad you figured it out! –  Josh Nov 7 '11 at 12:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.