Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Htaccess文件扩展名在重写中导致404_Php_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php Htaccess文件扩展名在重写中导致404

Php Htaccess文件扩展名在重写中导致404,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我的一条重写规则有问题。我正在开发一个应用程序,希望通过脚本控制文件访问。我的计划是简单地通过参数将重写规则传递给脚本,以检索适当的文件 但是,作为重写规则的一部分,我在尝试传递带有扩展名的文件名时遇到了一些问题。也许有人能指出我做错了什么 我的重写规则: RewriteEngine On RewriteBase / RewriteRule ^files/(.+)/(.*)$ /index.php/files/$1/$2 [NC,L] 工作原理:http://localhost/files/1

我的一条重写规则有问题。我正在开发一个应用程序,希望通过脚本控制文件访问。我的计划是简单地通过参数将重写规则传递给脚本,以检索适当的文件

但是,作为重写规则的一部分,我在尝试传递带有扩展名的文件名时遇到了一些问题。也许有人能指出我做错了什么

我的重写规则:

RewriteEngine On
RewriteBase /
RewriteRule ^files/(.+)/(.*)$ /index.php/files/$1/$2 [NC,L]
工作原理:http://localhost/files/12345/index

导致抛出404错误的原因:http://localhost/files/12345/index.css

我已经和它斗争了很长一段时间了,它几乎像是试图加载css文件,却找不到它,而且从未运行过rerwite规则。我在主机环境中使用IntelliJ的PHP内置Web服务器,不确定这是否与此有关

更新:

如果我去http://localhost/index.php/files/12345/index.css 页面直接按预期工作时,不会返回404。此规则是.htaccess文件中的唯一规则


如果我回显$_服务器[PATH_INFO];从index.php中,我得到/files/12345/index.css作为值返回

,您需要跳过此重写中的现有文件和目录:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(files/[^/]+/.*)$ /index.php/$1 [NC,L]

发现问题仅仅是PHP内置的Web服务器没有像apache一样尊重.htaccess。把它扔到一个成熟的apache服务器上,一切都很顺利。

这些文件/目录不存在,提供的htaccess也不能解决问题。你是说http://localhost/files/12345/index.css 不存在吗?怎么样http://localhost/index.php/files/12345/index.css??What 当你进入时会发生什么http://localhost/index.php/files/12345/index.css 直接在浏览器中?是否有任何其他规则,或者这是唯一的规则或任何其他规则。htaccessok是否可以打印echo$\u服务器[PATH\u INFO];从index.php查看它的打印目的http://localhost/files/12345/index.css URL?开始认为我使用的PHP内置Web服务器可能不完全支持.htaccess文件?有人能证实这一点吗?