Home > Backend Development > PHP Tutorial > .htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

.htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

WBOY
Release: 2023-03-02 12:38:01
Original
1381 people have browsed it

我的.htaccess文件配置

<code>RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1</code>
Copy after login
Copy after login

访问 local.com/admin/index解析正确

访问 资源文件 local.com/admin/index.css 时把资源文件当做了PATH_INFO请求,实际不存在这个CSS 文件应该报404错误。但是现在返回的是200

麻烦高手指点下我这种情况 .htaccess 文件给怎么配置


问题补充:

采用楼下这位哥 @xialeistudio 给的配置出现以下问题:

  1. 访问 frame.com/index.css 并不存在 index.css 出现了报错。ok

.htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

  1. 访问 frame.com/pathtest/index.css 并不存在 index.css 但是没有报错。

.htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

  1. 问题归纳:当访问根路径下不存在的资源文件是可以报错;但是访问不在根路径的不存在无资源文件时并没有报错。

回复内容:

我的.htaccess文件配置

<code>RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1</code>
Copy after login
Copy after login

访问 local.com/admin/index解析正确

访问 资源文件 local.com/admin/index.css 时把资源文件当做了PATH_INFO请求,实际不存在这个CSS 文件应该报404错误。但是现在返回的是200

麻烦高手指点下我这种情况 .htaccess 文件给怎么配置


问题补充:

采用楼下这位哥 @xialeistudio 给的配置出现以下问题:

  1. 访问 frame.com/index.css 并不存在 index.css 出现了报错。ok

.htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

  1. 访问 frame.com/pathtest/index.css 并不存在 index.css 但是没有报错。

.htaccess hides index.php and uses pathinfo to prevent resource file path errors without reporting errors.

  1. 问题归纳:当访问根路径下不存在的资源文件是可以报错;但是访问不在根路径的不存在无资源文件时并没有报错。

<code>RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpeg|gif)$
RewriteRule ^(.*)$ index.php/$1 [L]</code>
Copy after login

给你个配置参考下:

RewriteEngine on
RewriteBase /
RewriteRule (.*.css$|.*.js$|.*.jpg$|.*.gif$|.*.png$|.*.ico$|.*.swf$|.*.txt$) $1 [L]
RewriteRule (.*) index.php [L]

Related labels:
php
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template