【问题标题】:Slim route with parameter not working参数不工作的超薄路线
【发布时间】:2015-05-20 16:03:36
【问题描述】:

我正在尝试为我的应用程序设置 Slim,但我遇到了参数不起作用的问题。

这是我的index.php

require 'Slim/Slim.php';

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();


// GET route
$app->get('/', function () {
    print "hello";
});



$app->get('/books/:id', function ($id) {
    print $id;
});

$app->run();

这是.htaccess 文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

/ 的请求工作正常,但如果我通过/books/1 它会返回[404] not found

【问题讨论】:

  • mod_rewrite 是否启用?
  • 您是否收到了特定的错误/错误日志,如果是这种情况,请将其包含在问题中
  • @MikeRockett 是的,我在 apache 配置中有“AllowOverride all”
  • @MauricioGracia 我没有收到任何具体错误,只是找不到 404 页面
  • AllowOverride All 并不意味着启用了mod_rewrite - 它们彼此无关。检查LoadModule rewrite_module modules/mod_rewrite.so 是否在httpd.conf 中取消注释。

标签: php .htaccess slim


【解决方案1】:

您的 mod_rewrite 在 apache 中未启用。要启用 mod_rewrite,请按照此操作。参考 http://www.kingpabel.com/apache-mod-rewrite/

<Directory /var/www/html>
AllowOverride All
</Directory>

//enable mod rewrite
a2enmod rewrite

//restart apache
service apache2 restart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多