2012-07-11 34 views
13

我期待开发使用一个Drupal 7个网站,PHP内置的服务器。我已经成功地运行的Drupal没有清洁网址(例如的index.php?Q = /左右/),但清洁网址(例如/左右/)通常依赖于mod_rewrite的或它的等同物。在我看,你可以用一个路由器文件,像这样运行PHP服务器文档:服务的Drupal 7具有内置的PHP 5.4服务器

php -S localhost:8000 routing.php 

我应该放在routing.php模拟mod_rewrite的?

+0

+1一个有趣的问题。但由于这是该网站的开发副本,你真的需要干净的网址吗? (我假设它是一个网站的dev的副本....你不应该使用PHP的内置服务器直播系统! - 看到http://php.net/manual/en/features.commandline .webserver.php) – SDC 2012-07-11 12:58:15

+0

是的,只适用于dev。我使用Nginx和PHP-FPM进行部署。我也时不时做一个WordPress网站,它会有同样的问题。 – 2012-07-11 13:06:05

+1

在开发者网站上设置nginx和php-fpm有什么不对?它应该需要大约五分钟。 – 2012-07-11 18:17:55

回答

7

的任务基本上是编码Drupal的PHP中的.htaccess您router.php文件。

这里是一个开始:

<?php 

if (preg_match("/\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)/", $_SERVER["REQUEST_URI"])) { 
    print "Error\n"; // File type is not allowed 
} else 
if (preg_match("/(^|\/)\./", $_SERVER["REQUEST_URI"])) { 
    return false; // Serve the request as-is 
} else 
if (file_exists($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { 
    return false; 
} else { 
    // Feed everything else to Drupal via the "q" GET variable. 
    $_GET["q"]=$_SERVER["REQUEST_URI"]; 
    include("index.php"); 
} 

这应该被视为alpha质量。它表示通过Drupal 7.14的.htaccess文件步行3分钟,跳过需要超过10秒思考的任何事情。 :)

它,然而,让我推出Drupal的安装脚本,用样式表,JS和图像加载预期,并且使用清洁的网址打Drupal的页面。请注意,要在这种环境中安装 Drupal的,我需要a patch可能不会成为Drupal的一部分7.

+0

这看起来不错。你应该提交一个包含在Drupal中的补丁。 – 2012-07-11 19:59:17

+0

在普通请求上,SCRIPT_NAME是index.php,这意味着最后的else语句将永远不会执行。 – 2012-07-12 12:42:19

+0

@JasonChrista - 是的。如果我们正在处理对'index.php?q = admin'的请求,我们可能不想继续进行。我没看到什么吗? – ghoti 2012-07-14 01:01:24

3

我一直在寻找一个解决方案我自己,我发现一个在Drupal 8 issues

这个伟大的工程我现在在我现有的Drupal 7安装(S):

保存为.htrouter.php(或任何你愿意的话),并在你的Drupal根目录与运行:

php -S localhost:8080 .htrouter.php

<?php 
/** 
* @file 
* The router.php for clean-urls when use PHP 5.4.0 built in webserver. 
* 
* Usage: 
* 
* php -S localhost:8888 .htrouter.php 
* 
*/ 
$url = parse_url($_SERVER["REQUEST_URI"]); 
if (file_exists('.' . $url['path'])) { 
    // Serve the requested resource as-is. 
    return FALSE; 
} 
// Remove opener slash. 
$_GET['q'] = substr($url['path'], 1); 
include 'index.php'; 

(摘录自https://drupal.org/files/router-1543858-3.patch建)

3

现在,您可以更轻松地启动服务器的命令:

drush runserver

+0

这是唯一对我有用的答案。 'drush'必须是'drush.phar'的别名或符号链接,否则会出现无法在phar中找到文件的错误。 – contrebis 2016-10-21 09:54:19