[英]Serving Drupal 7 with built-in PHP 5.4 server
我期待使用PHP的內置服務器開發Drupal 7站點。 我已成功運行Drupal而沒有干凈的url(例如index.php?q = / about / )但是干凈的url(例如/ about / )通常依賴於mod_rewrite或它的等價物。 在文檔中,我看到你可以運行帶有路由器文件的PHP服務器,如下所示:
php -S localhost:8000 routing.php
我應該在routing.php中放置什么來模擬mod_rewrite?
任務基本上是用PHP編寫Drupal的.htaccess for 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和圖像按預期加載,並使用Clean URL命中Drupal的頁面。 請注意,要在此環境中安裝 Drupal,我需要一個可能不會成為Drupal 7一部分的補丁 。
我一直在尋找解決方案,我在Drupal 8問題中找到了一個解決方案:
在我現有的Drupal 7安裝中,這對我很有用:
保存為.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';
您現在可以使用以下命令更輕松地啟動服務器:
drush runserver
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.