: 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>
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.
More posts by @Debbie626
3 Comments
Sorted by latest first Latest Oldest Best
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/.
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.