PHPackages                             sylviavdv/router - 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. [Framework](/categories/framework)
4. /
5. sylviavdv/router

ActiveLibrary[Framework](/categories/framework)

sylviavdv/router
================

A simple router for PHP

1.0.0(today)00MITPHPPHP &gt;=8.1

Since Jun 27Pushed today1 watchersCompare

[ Source](https://github.com/sylviavdv/router)[ Packagist](https://packagist.org/packages/sylviavdv/router)[ RSS](/packages/sylviavdv-router/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Simple PHP Router
-----------------

[](#simple-php-router)

Route incoming HTTP requests to controller methods using PHP 8 attributes. Use regex, parameter requirements, and HTTP method filtering to define your routes.
The router automatically scans your controller classes caches the results for fast dispatching.

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

[](#requirements)

- PHP 8.1+

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

[](#installation)

```
composer require sylviavdv/router
```

Web server setup
----------------

[](#web-server-setup)

Rewrite all requests that you want the router to handle to a single file (eg. `index.php`).

For **Apache**, place an `.htaccess` file in your document root.

```
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
```

For **Nginx**, add the following to your server block.

```
location / {
    try_files $uri $uri/ /index.php;
}
```

Bootstrapping the router
------------------------

[](#bootstrapping-the-router)

Create an `index.php` in your document root.

```
