Download the PHP package brainstormdevel/basepath without Composer
On this page you can find all versions of the php package brainstormdevel/basepath. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brainstormdevel/basepath
More information about brainstormdevel/basepath
Files in brainstormdevel/basepath
Package basepath
Short Description A URL base path detector for Slim 4
License MIT
Homepage https://github.com/BrainStormDevel/basepath
Informations about the package basepath
selective/basepath
A URL base path detector for Slim 4.
Features
- Support for Apache and the PHP built-in webserver
- Tested
- No dependencies
- Very fast
Supported servers
- Apache webserver with mod_rewrite and .htaccess
- PHP build-in webserver
Requirements
- PHP 7.2+ or 8.0+
Installation
The recommended directory structure:
public/
Web server files, the DocumentRoot.htaccess
Apache redirect rules for the front controllerindex.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:
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:
Usage
Slim 4 integration
Add the BasePathMiddleware
after addRoutingMiddleware()
to set the basePath before
the routing is started.
Example: public/index.php
Apache usage
- Start the apache webserver
- Open your website, e.g.
http://localhost
orhttp://localhost/{my-sub-directory}
and you should see the messageHello, World!
.
PHP built-in webserver usage
- Open the console and change into the project
public/
directory. Then run:
If you don't start the webserver from the project public/
directory, you have start it with a specific document root directory:
- Open
http://localhost:8000
and you should see the messageHello, World!
.
Good URLs
The public/
directory is only the DoumentRoot
of your webserver,
but it's never part of your base path and the official url.
Good URLs:
https://www.example.com
https://www.example.com/users
https://www.example.com/my-app
https://www.example.com/my-app/users
Bad URLs:
https://www.example.com/public
https://www.example.com/public/users
https://www.example.com/my-app/public
https://www.example.com/my-app/public/users
Retrieving the base path
Creating a relative url with the base path
Rendering the base path into a Twig layout template
This example requires slim/twig-view
Support
- Issues: https://github.com/selective-php/basepath/issues
- Here you can donate for this project.
License
The MIT License (MIT). Please see License File for more information.