我知道在这个主题上已经有过几个类似的问题。我看过他们所有人,但没有人解决我的问题。这是我到目前为止所做的事情:
.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时,我得到的是:
我现在已经工作了大约2天,但我开始失去它。 任何帮助将不胜感激。 感谢。
答案 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'...