简体   繁体   English

CodeIgniter 作为 index.php 提供静态文件

[英]CodeIgniter serves static files as index.php

I'm running an existing php application with php -S 0.0.0.0:80 in a docker container for debug purposes.我正在 docker 容器中使用php -S 0.0.0.0:80运行现有的 php 应用程序以进行调试。 It uses CodeIgniter.它使用 CodeIgniter。 The link I'm going to is http://localhost/index.php and all the other assets are loaded with it as base url.我要访问的链接是http://localhost/index.php并且所有其他资产都将其作为基本 url 加载。 For example, http://localhost/assets/js/third-party-libraries/bootstrap/bootstrap.min.js .例如, http://localhost/assets/js/third-party-libraries/bootstrap/bootstrap.min.js But each file which comes back to the browser contains the same content as index.php .但是返回到浏览器的每个文件都包含与index.php相同的内容。

What am I missing in how CodeIgniter handles queries?我在 CodeIgniter 处理查询的方式中缺少什么?

PHP 7, CodeIgniter 3.1.9 PHP 7,代码点火器 3.1.9

PHP built-in web server doesn't use an .htaccess to know how to redirect files. PHP 内置 Web 服务器不使用 .htaccess 来了解如何重定向文件。 But it has a simple rule which needs to be implemented.但它有一个简单的规则需要执行。 The index.php can return false and this means the web server will return the resource as is. index.php可以返回false ,这意味着 Web 服务器将按原样返回资源。 From its documentation :从它的文档

<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
    return false;    // serve the requested resource as-is.
} else { 
    echo "<p>Welcome to PHP</p>";
}
?>

In the above example requests for images will display them, but requests for HTML files will display "Welcome to PHP".在上面的示例中,对图像的请求将显示它们,但对 HTML 文件的请求将显示“欢迎使用 PHP”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM