2013-10-23 21 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)