2014-02-06 34 views
2

我知道在這個主題上已經有幾個類似的問題。我已經看了他們所有的人,他們都沒有解決我的問題。這是我迄今所做的:Silex在localhost上的子目錄中:「對不起,找不到您正在查找的頁面」

  1. 使用虛擬主機已經被認爲(我不想,有以下幾個原因)
  2. 確信mod_rewrite的是(YES!,它是)
  3. 寫的包含默認 Silex Web服務器配置的.htaccess文件。發佈[這裏](http://silex.sensiolabs.org/doc/web_servers.html),幷包含在silex /目錄中。代碼低於
  4. 通過本地主機/〜username/silex成功到達了silex/web/index.php頁面(所以mod_rewrite絕對有效)。代碼如下
  5. 我回應出一個「這裏!」聲明和硅石/網絡/ index.php文件
  6. 我想一個解決方案,包括將第二.htaccess文件在硅石/網絡的/ DIR

.htaccess文件:

Options -MultiViews 
RewriteEngine On 
## this was uncommented because silex is in a subdir 
RewriteBase /~username/silex/web 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 

/silex/web/index.php文件:

require_once __DIR__.'/../vendor/autoload.php'; 

$app = new Silex\Application(); 

echo "HELLO"; 

$app->get('/', function() { 
    return 'Hello!'; 
}); 

$app->run(); 

當我到了硅石/網絡/的index.php這裏就是我得到:

Sorry, the page you are looking for could not be found

我一直在爲此工作了大約2天,現在開始失去它。 任何幫助將不勝感激。 謝謝。

+0

的http://本地主機/硅石/網絡/你好它將工作 – kn3l

回答

1

在你的.htaccess缺少目錄重寫條件,試試這個:

<IfModule mod_rewrite.c> 
    Options -MultiViews 
    RewriteEngine On 
    RewriteBase /~username/silex/web 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule^index.php [QSA,L] 
</IfModule> 

或使用

FallbackResource /~username/silex/web/index.php 

如果你的服務器運行的Apache> = 2.2.16。

+0

我已經看到了你給這個解決方案到類似的Silex .htaccess問題之前,我試了一下。它所做的只是允許/〜username/silex目錄被查看/編入索引。還試圖使用「FallbackResource」方法...仍然以相同的方案結束「對不起,您正在尋找的頁面找不到。」 – 80PoundsOfFury

0

擴展解決方案,您需要爲包含Silex(可能Symfony等)的子目錄創建一個htaccess並告訴Apache如何解釋路由。套用crzpata's Gist

<IfModule mod_rewrite.c> 
RewriteEngine on 
#UNCOMMENT next line if silex app root is in a mamp subdirectory 
#RewriteBase /your_mamp_htdocs_silex_app_root 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^web/index.php [L] 
</IfModule> 

然後定義您的硅石航線使用定義根:

$app->get('/directory_in_silex_root'... 
相關問題