2013-10-23 20 views
2

我在我的电脑访问:http://www.laji.com
有www文件夹如何禁止img文件重写?

的.htaccess

Options +FollowSymLinks 
RewriteEngine on 
RewriteBase/

# All other pages 
# Don't rewrite real files or directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^.*(\.css|\.js|\.gif|\.png|\.jpg|\.jpeg)$ 
RewriteRule ^(.*)$ index\.php?main_page=$1&%{QUERY_STRING} [L] 

的index.php

<?php echo $_GET['main_page'] ?> 
当我访问 http://wwww.laji.com/xxx.jpg

(这JPG下2个文件是不存在的),它重写为index.php?main_page = xxx.jpg,但我想让它显示404信息,不需要重写,为什么我的htaccess代码不起作用?

+1

我收到了404当我去到一个不存在的使用规则JPG –

+0

@ mingfish_004是个是你的htaccess中唯一的代码还是你还有其他规则? – anubhava

+0

只有代码,没有其他人 –

回答

0

你能尝试改变:

RewriteCond %{REQUEST_URI} !^.*(\.css|\.js|\.gif|\.png|\.jpg|\.jpeg)$ 

到:

RewriteCond %{REQUEST_URI} !\.(css|js|gif|png|jpg|jpeg)$ 

,让我知道,如果它的工作。

如果不工作,我想你可能需要添加一行(靠近的.htaccess的顶部)是这样的:

ErrorDocument 404 "Not found!" 

如果你搞不定,你可以添加自定义错误404文件这样的(而不是在报价上面的文字):

ErrorDocument 404 /error_404.html 

参考:Set web server handle 404 errors for some file types using .htaccess (ErrorDocument 404 + rewrite rules)