承接 middlewares/base-path 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

middlewares/base-path

最新稳定版本:v2.2.0

Composer 安装命令:

composer require middlewares/base-path

包简介

Middleware to remove the prefix from the uri path of the request.

README 文档

README

Latest Version on Packagist Software License Testing Total Downloads

Middleware to remove the prefix from the uri path of the request. This is useful to combine with routers if the root of the website is in a subdirectory. For example, if the root of your website is /web/public, a request with the uri /web/public/post/34 will be converted to /post/34.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/base-path.

composer require middlewares/base-path

Usage

Set the prefix to remove:

Dispatcher::run([
    new Middlewares\BasePath('/base/path')
]);

fixLocation

Used to add the prefix to the Location header (for redirects). For example:

$response = Dispatcher::run([
    (new Middlewares\BasePath('/base/path'))->fixLocation(),

    function () {
        return Factory::createResponse(301)->withHeader('Location', '/post/1');
    }
]);

echo $response->getHeader('Location'); // Returns /base/path/post/1

attribute

This method will store the original path in an attribute.

// Save the original uri with basepath in the custom attribute "before-basepath-uri"
$basepath = (new Middlewares\BasePath())->attribute('pre-basepath-path');

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 1.33M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04