简体   繁体   English

参数不起作用的细线

[英]Slim route with parameter not working

I'm trying to setup Slim for me application i've got issue that route with parameters not working. 我正在尝试为我的应用程序设置Slim ,但我遇到了无法使用参数的路由问题。

This is my index.php 这是我的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();

This is the .htaccess file 这是.htaccess文件

RewriteEngine On

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

Request to / works fine, but if I pass /books/1 it returns [404] not found 要求/工作正常,但如果我通过/books/1则返回[404]找不到

Man your mod_rewrite is not enable in apache.For enable mod_rewrite follow this.Reference http://www.kingpabel.com/apache-mod-rewrite/ 请确保您的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM