[英]use .htaccess with php5.4 built-in server
在我的開發環境中,我使用了php5.4的內置Web服務器,但是.htaccess似乎無法正常工作。 我找不到該服務器的文檔。 有人可以告訴我是否可以像Apache一樣使用htaccess和mod_rewrite嗎?
非常感謝你
就像我在評論中提到的那樣,當前目錄默認是您的webroot。 此外,此網絡服務器不支持.htaccess
。
您會在這里找到有關您的問題的很好的解釋 。
使服務器運行
默認情況下,當前目錄是您的webroot,現在您可以請求此處的任何文件,並以通常的方式運行PHP
要么
像Apache Rewrite這樣的路由請求
我一直在尋找的一項直接功能是能夠將所有傳入請求重定向到index.php,這通常是使用.htaccess文件完成的。 該Web服務器不支持這些服務器(盡管我的好朋友Josh已經創建了一些文件),但是它確實支持路由文件。
我不喜歡這樣做,但是我已經通過Magento軟件在野外看到了它:
/**
* Parse .htaccess file and apply php settings to shell script
*
*/
protected function _applyPhpVariables()
{
$htaccess = $this->_getRootPath() . '.htaccess';
if (file_exists($htaccess)) {
// parse htaccess file
$data = file_get_contents($htaccess);
$matches = array();
preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
if ($matches) {
foreach ($matches as $match) {
@ini_set($match[1], str_replace("\r", '', $match[2]));
}
}
preg_match_all('#^\s+?php_flag\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
if ($matches) {
foreach ($matches as $match) {
@ini_set($match[1], str_replace("\r", '', $match[2]));
}
}
}
}
它的目的是將.htaccess
PHP設置應用於PHP CLI腳本,但我想它也應適用於PHP的內置Web服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.