PHPackages                             brainstormdevel/basepath - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. brainstormdevel/basepath

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

brainstormdevel/basepath
========================

A URL base path detector for Slim 4

2.0.5(10mo ago)06531MITPHPPHP ^7.2 || ^8.0

Since Aug 21Pushed 10mo agoCompare

[ Source](https://github.com/BrainStormDevel/basepath)[ Packagist](https://packagist.org/packages/brainstormdevel/basepath)[ Docs](https://github.com/BrainStormDevel/basepath)[ RSS](/packages/brainstormdevel-basepath/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (8)Versions (12)Used By (0)

selective/basepath
==================

[](#selectivebasepath)

A URL base path detector for Slim 4.

[![Latest Version on Packagist](https://camo.githubusercontent.com/81ed6691a0c0d9a1bb6bec6c28f8375547011a36fb992240794e4023c38bd948/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f627261696e73746f726d646576656c2f62617365706174682e737667)](https://packagist.org/packages/brainstormdevel/basepath)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/brainstormdevel/basepath/workflows/build/badge.svg)](https://github.com/brainstormdevel/basepath/actions)[![Coverage Status](https://camo.githubusercontent.com/9b8b94baba85e488c80fd48889e5ff6ac6f59071d1cb0c874c19e5228541cbb0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f627261696e73746f726d646576656c2f62617365706174682e737667)](https://scrutinizer-ci.com/g/brainstormdevel/basepath/code-structure)[![Quality Score](https://camo.githubusercontent.com/e302cba478088feeb794a0307d70c51dd04aa651258bc08bf52799ff831d2649/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f627261696e73746f726d646576656c2f62617365706174682e737667)](https://scrutinizer-ci.com/g/brainstormdevel/basepath/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/7892027dd32324c8fdd2e4cebfdd5d79c339c03d5ab91bf07e3cc96fdfed0daf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f627261696e73746f726d646576656c2f62617365706174682e737667)](https://packagist.org/packages/brainstormdevel/basepath/stats)

Features
--------

[](#features)

- Support for Apache and the PHP built-in webserver
- Tested
- No dependencies
- Very fast

### Supported servers

[](#supported-servers)

- Apache webserver with mod\_rewrite and .htaccess
- PHP build-in webserver

Requirements
------------

[](#requirements)

- PHP 7.2+ or 8.0+

Installation
------------

[](#installation)

```
composer require brainstormdevel/basepath

```

The recommended **directory structure**:

- `public/` Web server files, the [DocumentRoot](https://httpd.apache.org/docs/2.4/de/mod/core.html#documentroot)
    - `.htaccess` Apache redirect rules for the front controller
    - `index.php` The front controller
- `.htaccess` Internal redirect to the public/ directory

The following steps are necessary for your Slim 4 application:

For **Apache** we have to "redirect" the web traffic to the front controller in `public/index.php`.

Create a file: `public/.htaccess` with this content:

```
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

```

We also need a rule to "redirect" the sub-directories to the front-controller in `public/index.php`.

Create a second `.htaccess` file above the `public/` directory with this content:

```
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

```

Usage
-----

[](#usage)

### Slim 4 integration

[](#slim-4-integration)

Add the `BasePathMiddleware` after `addRoutingMiddleware()` to set the basePath before the routing is started.

Example: `public/index.php`

```
