php - PHP 5.4 内置服务器上的友好 URL

标签 php php-builtin-server

我通常使用 Apache 作为我的 php 应用程序的网络服务器。但我刚刚发现 php 5.4 带有一个内置的网络服务器。

在我尝试加载 php -S 的第一个应用程序中,我注意到重写规则未启用或无法正常工作。

有人知道内置服务器有没有这样的东西?

最佳答案

来自Built-in web server手册部分:

If a PHP file is given on the command line when the web server is started it is treated as a "router" script. The script is run at the start of each HTTP request. If this script returns FALSE, then the requested resource is returned as-is. Otherwise the script's output is returned to the browser.

路由器文件

<?php
// routing.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
    return false;
} else {
    include __DIR__ . '/index.php';
}

然后启动服务器:

php -S localhost:8888 routing.php

来源:http://gonzalo123.com/2012/10/15/how-to-rewrite-urls-with-php-5-4s-built-in-web-server/

重要提示

This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

关于php - PHP 5.4 内置服务器上的友好 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21860727/

相关文章:

java - ACRA 未通过 HTTPSender 发送

php - 从 MySQLi 字段获取类型规范字符

php - 从 PHP 内置网络服务器使用 shell_exec 运行后台进程

php - 防止 Symfony2 内置服务器死机

php - phpMyAdmin 的单点登录

javascript - 设置 php 中执行的 phantomjs 的超时时间

php - php负载均衡

symfony - 如何避免终端捕获错误而不是Symfony探查器

fat-free-framework - 使用 PHP 内置 Web 服务器的 Fatfree 路由