views:

193

answers:

2

I have this in my .htaccess file:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule !\.(gif|jpg|png|css|js|ico|flv|php|txt)$ index.php

Now i need to add another rule that will forward to index.html if no REQUEST_FILENAME is found.

So www.mysite.com would forward to index.html and www.mysite.com/file.html would forward to index.php.

+1  A: 

I normaly use this rewrite rules:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

It rewrites all urls which dont exist to the index.php.

Rufinus
So how do I forward to index.html and not to index.php if there is no file in request url?
dfilkovi
why you want to do this with rewrite ? you can have a index.html and a index.php in your documentroot. if you set DirectoryIndex index.html then index.html will be called if you dont have a request_filename.
Rufinus
index.php is my front controller, and index.html holds a entry flash animation for a web site so all requests are forwarded to index.php and now i need a single request that has no request_filename to forward to index.html
dfilkovi
exactly what i told you... http://www.foobar.de -> index.htmlhttp://www.foobar.de/whatsoever -> index.php
Rufinus
+1  A: 

Just add another rule without the restrictions in the URL path ending:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(gif|jpg|png|css|js|ico|flv|php|txt)$ index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html

But it would probably be better to use the default error handling with:

ErrorDocument 404 /index.html

Otherwise your server won’t respond with a 404 on a request of a non existing file.

Gumbo
Doesn't work, If I add:RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^ index.htmlat the end it loads index.php every time, and if I put it before, it always loads index.html
dfilkovi
@dfilkovi: What’s the purpose of the first rule anyway?
Gumbo
index.php is my front controller, and index.html holds a entry flash animation for a web site so all requests are forwarded to index.php and now i need a single request that has no request_filename to forward to index.html
dfilkovi
@dfilkovi: But the first rule does already rewrite those requests. Only if you request a URL that does not fit the pattern of the first rule the second one will be applied.
Gumbo