【问题标题】:htaccess config for slim php framework用于苗条 php 框架的 htaccess 配置
【发布时间】:2015-01-28 05:18:20
【问题描述】:

我使用 Slim php 框架在 index.php 页面中构建一些操作: 所以这就是我称之为行动的方式:

index.php/action1

$app->get('/action1',function () use ($app){
            echo "this is action 1";
});

index.php/action2

$app->get('/action2',function () use ($app){
            echo "this is action 2";
});

现在我希望我的 url 变得漂亮,例如当输入 index/action1

,它将重定向到 index.php/action1
请为我提供创建 htaccess 的解决方案
感谢并衷心感谢

【问题讨论】:

    标签: php regex .htaccess slim


    【解决方案1】:

    创建.htaccess 文件

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

    为您的路线添加前缀的用户组

    $app->group('/index', function () use ($app) {
        /**
         * Route GET /index/action1
         */
        $app->get('/action1',function () use ($app){
            echo "this is action 1";
        });
    });
    

    【讨论】:

    • 谢谢。但是这样隐藏“索引”页面。我想保留“索引”名称,因为将来我想添加许多其他页面。
    猜你喜欢
    • 2012-12-04
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多