刚开始使用 Silex,遇到一些问题。
下载 fat zip file , 解压缩到 wamp
的 www
文件夹。所以,这里是 C:\wamp\www\fat-silex\web\index.php
:
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello', function() {
return 'Hello!';
});
$app->run();
问题是我正在为 http://localhost/fat-silex/web/hello
获取 Apache 的 404 ,以及除 localhost/fat-silex/web
之外的任何 URL ,在那里我得到了 Silex 的 404(如预期的那样)。我猜这些请求直接发送到 Apache,而不是由 Silex 路由。这看起来问题可以用 .htaccess
解决。文件,所以我添加了这个,在 official documentation 中建议:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /fat-silex
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
但是,它似乎根本没有任何效果。
最佳答案
你的重写基础应该是/fat-silex/web
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /fat-silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
我已经在我的本地主机上测试过了,它工作正常
关于php - 我为什么要购买这些 Silex 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15498419/