我为什么要买这些Silex 404?

Mih*_*aru 3 php apache .htaccess wamp silex

刚开始使用Silex并遇到一些问题.

下载的脂肪压缩文件,解压成wampwww文件夹中.所以,这是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();
Run Code Online (Sandbox Code Playgroud)

问题是我正在获取Apache的404 http://localhost/fat-silex/web/hello,以及任何URL,除了localhost/fat-silex/web我正在获得Silex'es 404(正如预期的那样).我猜这些请求直接发送到Apache,并且不会被Silex路由.看起来问题可以用.htaccess文件解决,所以我在官方文档中建议添加了这个:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase /fat-silex
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

但是,它似乎没有任何影响.

Ada*_*ney 5

你的改写基础应该是 /fat-silex/web

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteBase /fat-silex/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

我在我的localhost上测试了它,它运行正常

  • 终于搞定了 - "mod_rewrite"没有启用.我在Ubuntu VM中追踪了这个问题 - 并用`sudo a2enmod rewrite`修复了它,然后注意到我的Windows`WAMP`设置中没有启用`mod_rewrite`.启用它(右键单击Apache Modules - >检查`rewrite_module`或来自`httpd.conf`),一切都很好.在Ubuntu上需要执行`AllowOverride`,但在`WAMP`上不需要. (2认同)