PHPackages                             sagittariusx/beluga.routing - 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. sagittariusx/beluga.routing

ActiveLibrary

sagittariusx/beluga.routing
===========================

Simple URL routing library.

0.1.1(9y ago)114LGPLv3PHPPHP &gt;=7.0

Since Aug 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SagittariusX/Beluga.Routing)[ Packagist](https://packagist.org/packages/sagittariusx/beluga.routing)[ RSS](/packages/sagittariusx-belugarouting/feed)WikiDiscussions master Synced today

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

Beluga.Routing
==============

[](#belugarouting)

Simple URL routing library.

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

[](#installation)

Install it via composer!

```
composer require sagittariusx/beluga.routing
```

or include it inside you're composer.json

```
{
   "require": {
      "php": ">=7.0",
      "sagittariusx/beluga.": "^0.1.1"
   }
}
```

Preparing the web server
------------------------

[](#preparing-the-web-server)

For Router usage you need to tell the web server, that it should rewrite requests to not existing URL paths to the handling PHP script.

You can do it by 2 different ways:

- Passing the not existing URL path as `GET` variable with specific name, to the script
- Passing the not existing URL path VIA `$_SERVER[ 'REQUEST_URI' ]` (best choice)

### Apache web server

[](#apache-web-server)

For apache its really simple to handle the rewrites.

Create an file with the name `.htaccess` and put it to the folder where the rewriting should work.

But remember!

.htaccess (distributed configuration files) should only be used if you do'nt have access to the server configuration files.

.htaccess usage comes with some overhead which can be avoided.

But if you admit an server, there is no need to shown you more. You have to know it :-)

The contents of this file depends to the Router type that should be used.

#### As GET variable (RouterType::REWRITE\_TO\_GET)

[](#as-get-variable-routertyperewrite_to_get)

```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?theURL=$1 [QSA,L]

```

The first line enables the rewrite engine. Second line declares the condition that matches all not existing file calls and the third line matches all not existing directory calls.

The last line rewrites the matching calls to not existing files and directories to `index.php` and passes the called, not existing URL path to the `theURL` GET variable

#### As 'REQUEST\_URI' value (RouterType::REWRITE\_TO\_REQUEST\_URI)

[](#as-request_uri-value-routertyperewrite_to_request_uri)

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

```

The first line enables the rewrite engine. Second line declares the condition that matches all not existing file calls and the third line matches all not existing directory calls.

The last line rewrites the matching calls to not existing files and directories to `index.php` and the called. not existing URL path is passed to `$_SERVER[ 'REQUEST_URI' ]`

#### On errors

[](#on-errors)

If the .htaccess usage triggers some server errors (e.g. error 50\* or something else) you have to check:

- if apache is enabled to use .htaccess files
- if apache is enabled to use rewriting by .htaccess files (Rights for .htaccess stuff)
- if apache is enabled to use the mod\_rewrite extension

The first 2 things can be handled by ensure the AllowOverwrite directive. For details see: [Apache HTTP Server Tutorial: .htaccess files](https://httpd.apache.org/docs/current/howto/htaccess.html)

```
AllowOverride FileInfo

```

To check if mod rewrite is enable call this inside you're console

```
sudo a2enmod rewrite
```

If already enabled it outputs: `Module rewrite already enabled`

If not enabled, the rewrite module gets enabled.

If you not have access to call a console at the server contact the admin or provider and ask him if mod\_rewrite is enabled for you. If not please him to enable the mod\_rewrite usage via .htaccess

### NGINX web server

[](#nginx-web-server)

This is a big TODO! :-)

but i think if you use:

```
try_files $uri $uri/ /index.php?$args;

```

…it should work to get the called URL path via `$_SERVER[ 'REQUEST_URI' ]` inside `index.php`

Usage
-----

[](#usage)

```
// Include the autoloader, created by composer
require __DIR__ . '/vendor/autoload.php';

use Beluga\Routing\Router;
use Beluga\Routing\RouterType;

// Init the router
$router = new Router(
   // The type of the router
   RouterType::REWRITE_TO_REQUEST_URI
);

// Adds an dynamic regex URI path route
$router->addRoute(
   '~^/foo/(\d+)/bar/?$~',
   function ( array $matches )
   {
      // If you need access to current Router instance can get it by Router::GetInstance()
      echo 'ID: ', $matches[ 1 ], ' OK :-)';
      exit;
   }
);

// Adds an static URI path route
$router->addRoute(
   '~^/baz/?$~',
   function ()
   {
      // If you need access to current Router instance can get it by Router::GetInstance()
      echo 'The BAZ is called!';
      exit;
   }
);
```

After defining you're routes you only should call execute() and the routes will be executed.

```
if ( ! $router->execute() )
{
   // Showing 404 error because no router matches the defined request URI path.
}
```

###  Health Score

23

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3513d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccdb1997342e9edfb20d481ebea751f251b7ef837c7a8622e6b464f56243a0f4?d=identicon)[SagittariusX](/maintainers/SagittariusX)

---

Top Contributors

[![UniKado](https://avatars.githubusercontent.com/u/6945587?v=4)](https://github.com/UniKado "UniKado (4 commits)")[![SagittariusX](https://avatars.githubusercontent.com/u/20841191?v=4)](https://github.com/SagittariusX "SagittariusX (1 commits)")

### Embed Badge

![Health badge](/badges/sagittariusx-belugarouting/health.svg)

```
[![Health](https://phpackages.com/badges/sagittariusx-belugarouting/health.svg)](https://phpackages.com/packages/sagittariusx-belugarouting)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
