开发者

mod_rewrite empty REQUEST_FILENAME

I have this in my .htaccess file:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRul开发者_如何学Goe !\.(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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜