【问题标题】:Getting Slim routes to work using grunt-contrib-connect and connect-modrewrite-jgchristian使用 grunt-contrib-connect 和 connect-modrewrite-jgchristian 让 Slim 路由正常工作
【发布时间】:2015-11-04 23:47:58
【问题描述】:

我正在使用connect-modrewrite-jgchristian,因为它应该正确地传递 QSA 标志。截至目前,索引页面有效,但内部页面均无效。这是 Slim 的库存 .htaccess 文件:

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

直接使用这个会加载索引页面:

rewrite(['%{REQUEST_FILENAME} !-f ^ index.php [QSA,L]'])

尝试访问 http://127.0.0.1:9000/news 会引发无法 GET 错误:

Cannot GET /news

这工作得稍微好一点 - 当你转到 /news 时它会加载 index.php,但不会触发路由:

rewrite(['!\\.php|\\.html|\\.js|\\.css|\\.svg|\\.jp(e?)g|\\.png|\\.gif$ /index.php [QSA,L]'])

为了更好的衡量,这是我的 Slim 路线,虽然我很确定它不会走这么远:

$app->get('/', function () use($app, $smarty) {
   $app->render('home.tpl', array('ParentTemplate' => $smarty->compile_id . '.tpl'));
})->name('home');

$app->get('/news', function () use($app, $smarty) {
   $app->render('news.tpl', array('ParentTemplate' => $smarty->compile_id . '.tpl'));
})->name('news');

有人试过这样的吗?我一时难过。

更新

我发现它只能与正则表达式第二个示例一起使用,但看起来它仍然没有传递 slim 访问正确路由所需的任何信息。

更新 2

这可以追溯到 grunt-contrib-connect 处理 $_SERVER 变量的方式(我认为)。这是常规的 apache:

'SCRIPT_NAME' => string '' (length=0)
'PATH_INFO' => string '/about' (length=6)

connect的服务器只有:

["SCRIPT_NAME"]=>  string(1) "/"

Slim 将 PATH_INFO 设置为 $requestUri,所以弄清楚如何在 connect 中设置它我认为应该可以解决问题。现在正在努力。

【问题讨论】:

    标签: gruntjs rewrite slim


    【解决方案1】:

    切换到 grunt-php 并开始工作。

    【讨论】:

      猜你喜欢
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 2013-12-28
      • 2017-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多