Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何禁止img文件重写?_Php_.htaccess - Fatal编程技术网

Php 如何禁止img文件重写?

Php 如何禁止img文件重写?,php,.htaccess,Php,.htaccess,我电脑中的域名是: www文件夹下有2个文件 .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} !^

我电脑中的域名是:
www文件夹下有2个文件

.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'] ?>


当我访问(这个jpg不存在)时,它被重写为index.php?main_page=xxx.jpg,但我想让它显示404信息,不需要重写,为什么我的htaccess代码不工作?

你能尝试更改:

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

让我知道它是否有效

如果不工作,我认为您可能需要添加一行(靠近.htaccess顶部),如下所示:

ErrorDocument 404 "Not found!"
如果你让它工作,你可以添加一个自定义的错误404文件(而不是上面引号中的文本):


参考资料:

当我使用您的手机访问一个不存在的jpg时,我会得到一个404rules@mingfish_004这是您的htaccess中唯一的代码,还是您还有其他规则?您可以尝试在.htaccess顶部的
Options+FollowSymLinks-MultiViews
替换您的选项行.trued,得到相同的结果吗
ErrorDocument 404 "Not found!"
ErrorDocument 404 /error_404.html