2

我电脑中的域是:http
://www.laji.com 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]

索引.php

<?php echo $_GET['main_page'] ?>

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

4

1 回答 1

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

参考:使用 .htaccess 为某些文件类型设置 Web 服务器句柄 404 错误(ErrorDocument 404 + 重写规则)

于 2014-01-22T08:30:23.870 回答