本地主机上的子目录中的Silex:“抱歉,找不到您要查找的页面”

时间:2014-02-06 00:37:05

标签: apache .htaccess localhost silex

我知道在这个主题上已经有过几个类似的问题。我看过他们所有人,但没有人解决我的问题。这是我到目前为止所做的事情:

  1. 已经考虑使用虚拟主机(我不想,出于几个原因)
  2. 确保mod_rewrite已开启(YES,它是!)
  3. 编写了一个包含默认值的.htaccess文件  Silex Webserver配置。发布[here](http://silex.sensiolabs.org/doc/web_servers.html)并包含在silex /目录中。
  4. 下面的代码
  5. 通过localhost / ~username / silex成功访问了silex / web / index.php页面(因此mod_rewrite绝对有效)。以下代码
  6. 我在这里回答了一个问题!"语句和silex / web / index.php
  7. 我尝试了一个解决方案,包括在silex / web / dir中放置第二个.htaccess文件
  8. .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();
    

    当我到达silex / web / index.php时,我得到的是:

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

    我现在已经工作了大约2天,但我开始失去它。 任何帮助将不胜感激。 感谢。

3 个答案:

答案 0 :(得分:3)

啊哈!我在这里找到了答案 - > MAMP Silex htaccess

我希望这个解决方案可以帮助其他人解决我的痛苦! :)

答案 1 :(得分: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&gt; = 2.2.16。

答案 2 :(得分: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>

然后使用定义的root来定义您的silex路由:

$app->get('/directory_in_silex_root'...