Home> php教程> PHP开发> body text

How to force jpg, js, css and other resources to connect, if they do not exist, directly 404 without rewriting

高洛峰
Release: 2016-11-24 13:48:00
Original
1194 people have browsed it

怎么强制jpg,js,css等连接资源,如果不存在就直接404而不重写
我在本机架设了个网站
http://www.laji.com
网站文件夹下有2个文件,
.htaccess文件:

Options +FollowSymLinks -MultiViews
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]
Copy after login

index.php

Copy after login

我使用http://www.laji.com/xxx.jpg (这个图片不存在),为什么还是被重写指向

http://www.laji.com/index.php?main_page=xxx.jpg?
怎么强制jpg,js,css等连接资源,如果不存在就直接404而不重写

分享到:


------解决方案--------------------
-s判断请求的文件是否是一个存在的非空文件;判断不是可以用:!-s


RewriteCond %{REQUEST_FILENAME} !-s
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!