.htaccess 隐藏index.php 并使用pathinfo 资源文件路径错误不报错
本文介绍了.htaccess 隐藏index.php 并使用pathinfo 资源文件路径错误不报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我的.htaccess文件配置
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1
访问 local.com/admin/index解析正确
访问 资源文件 local.com/admin/index.css 时把资源文件当做了PATH_INFO请求,实际不存在这个CSS 文件应该报404错误。但是现在返回的是200
麻烦高手指点下我这种情况 .htaccess 文件给怎么配置
问题补充:
采用楼下这位哥 @xialeistudio 给的配置出现以下问题:
访问
frame.com/index.css
并不存在 index.css 出现了报错。ok
访问
frame.com/pathtest/index.css
并不存在 index.css 但是没有报错。
问题归纳:当访问根路径下不存在的资源文件是可以报错;但是访问不在根路径的不存在无资源文件时并没有报错。
解决方案
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|gif)$
RewriteRule ^(.*)$ index.php/$1 [L]
这篇关于.htaccess 隐藏index.php 并使用pathinfo 资源文件路径错误不报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文