簡體   English   中英

使用Slim框架重定向

[英]Redirect with Slim Framework

我有以下代碼:

$app->get('/category/:name', function($name){
  //the render files are found under the templates folder
header('Location: searchPage.php?crs_category=$name');
});

問題是當我鍵入/category/business它僅落在空白頁上。 我不想呈現頁面,因為我無法完全呈現searchPage.php?crs_category,因為它是作為模板查看的,並且可以解決將變量包含在內的問題。 我只想直接轉到該頁面,同時保持網址干凈。 本質上是在后台重定向到此頁面,並保留該URL。

提前致謝。

假設您將Apache用作網絡服務器,是否不能只重寫.htaccess的URL:

RewriteRule ^category/(.*)$ searchPage.php?crs_category=$1 [L,NC,QSA]

..或者如果您想進行真正的重定向

RewriteRule ^category/(.*)$ searchPage.php?crs_category=$1 [L,NC,R=301]

PS:如果您堅持在Slim中進行操作,則可以嘗試

$app->get('/category/:name', function($name) use ($app) {
    $app->response->redirect('/searchPage.php?crs_category='.$name, 303);
});

來源: http : //docs.slimframework.com/response/helpers/#redirect

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM