Heim  >  Artikel  >  Backend-Entwicklung  >  怎么强制jpg,js,css等连接资源,如果不存在就直接404而不重写

怎么强制jpg,js,css等连接资源,如果不存在就直接404而不重写

WBOY
WBOYOriginal
2016-06-23 14:24:52830Durchsuche

我在本机架设了个网站
http://www.laji.com
网站文件夹下有2个文件,
.htaccess文件:

Options +FollowSymLinks -MultiViewsRewriteEngine onRewriteBase /# All other pages# Don't rewrite real files or directoriesRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{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://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  


可以试试

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn