Mobile app version of vmapp.org
Login or Join
Debbie626

: Mod rewrite condition !-f being violated 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>

@Debbie626

Posted in: #ModRewrite

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= [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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Debbie626

3 Comments

Sorted by latest first Latest Oldest Best

 

@Debbie626

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/.

10% popularity Vote Up Vote Down


 

@RJPawlick198

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= [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.

10% popularity Vote Up Vote Down


 

@Miguel251

If you simply want to perform a redirect, use

Redirect 301 /index.html www.example.com/index.php

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme