php - 我为什么要购买这些 Silex 404?

标签 php apache .htaccess wamp silex

刚开始使用 Silex,遇到一些问题。

下载 fat zip file , 解压缩到 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();

问题是我正在为 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/

相关文章:

PHP mysql 查询不工作

javascript - 使用 PHP 处理表单中的多个复选框?

html - 样式表和隐藏 .html 扩展名

php - htaccess 图片 url 重写规则

php - Codeigniter 2.1,MySQL - 两个左连接

php - 如何在 Cake 3 的表模型文件中设置数据源?

php - WAMP 服务器在全新安装时切换 Apache/PHP 版本时出错

java - 我无法访问 Apache Tomcat 管理器?

apache - 更新 SSL 证书后出现错误。 Apache 网络服务器

.htaccess - 如何使用 .htaccess 将子域别名/重定向到另一个域子文件夹