PHPackages                             byteflick/laravel-strict-domain - 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. [Security](/categories/security)
4. /
5. byteflick/laravel-strict-domain

ActiveLibrary[Security](/categories/security)

byteflick/laravel-strict-domain
===============================

Domain Checker Package for Laravel that ensures seamless redirection to a specified domain, optimizing security and user experience within Laravel applications.

v3.0.1(2y ago)8973[5 PRs](https://github.com/ByteFlick/laravel-strict-domain/pulls)MITPHPPHP ^8.1CI passing

Since Mar 16Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/ByteFlick/laravel-strict-domain)[ Packagist](https://packagist.org/packages/byteflick/laravel-strict-domain)[ Docs](https://github.com/byteflick/laravel-strict-domain)[ GitHub Sponsors](https://github.com/ByteFlick)[ RSS](/packages/byteflick-laravel-strict-domain/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (9)Versions (12)Used By (0)

[![](https://github.com/ByteFlick/.github/raw/main/profile/btye-flick-logo.png?raw=true)](https://github.com/ByteFlick/.github/blob/main/profile/btye-flick-logo.png?raw=true)

Strict Domain Checking for Laravel
==================================

[](#strict-domain-checking-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8fb10669ad0bb64f4e2c7ea51ae2ba4759897bd048f118bac435624f2162d0a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f42797465466c69636b2f6c61726176656c2d7374726963742d646f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/byteflick/laravel-strict-domain)[![GitHub Tests Action Status](https://camo.githubusercontent.com/38e07c53b9d8216dd9a2e8e046811b217dd94be1b0a930a9101c73ed0a04bf2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f42797465466c69636b2f6c61726176656c2d7374726963742d646f6d61696e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ByteFlick/laravel-strict-domain/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/4b3af4e993d8c03cb43ba83836567f19c405cb423f7305fe904cd1ab0c4876cb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f42797465466c69636b2f6c61726176656c2d7374726963742d646f6d61696e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/byteflick/laravel-strict-domain/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/16b6e28298c79f7b55b3d415174b8d6794ecb703ef4553e2c2f39f05824f11fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f42797465466c69636b2f6c61726176656c2d7374726963742d646f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/byteflick/laravel-strict-domain)

Strict Domain Checking for Laravel is a lightweight package designed to seamlessly integrate with Laravel applications, providing a simple solution for domain-based redirection. With this package, you can ensure that incoming traffic to your Laravel application is redirected to a specified domain if the requesting domain doesn't match the configured domain. By implementing a customizable middleware, developers can easily enforce domain consistency, enhancing security and user experience. Whether managing multiple domains or enforcing branding standards, this package offers a flexible and efficient solution for domain redirection within Laravel applications.

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

[](#installation)

You can install the package via composer:

```
composer require byteflick/laravel-strict-domain
```

You can publish the config file with (Optional):

```
php artisan vendor:publish --provider="ByteFlick\LaravelStrictDomain\LaravelStrictDomainServiceProvider"
```

This is the contents of the published config file:

```
return [
    'include_sub_domains' => true,
    'domain' => env('APP_DOMAIN', 'localhost.com'),
];
```

Usage
-----

[](#usage)

### Step 1: Configure the Environment

[](#step-1-configure-the-environment)

You need to add an environment variable called `APP_DOMAIN` to your `.env` file. The value of this variable is used for validating the incoming traffic.

```
APP_DOMAIN=localhost.com
```

### Step 2: Apply the Middleware

[](#step-2-apply-the-middleware)

#### 2.1 Redirecting External Traffic

[](#21-redirecting-external-traffic)

If you want to redirect incoming traffic to your application from other domain/hosts to your own then you can use `RedirectExternalTraffic` middleware. This is useful when you want to redirect all the traffic from `johndoe.com` ( referrer domain) and other domains/hosts to `janedoe.com` (your designated domain).

##### On Specific Routes Only

[](#on-specific-routes-only)

You can add the middleware to individual routes or apply it via a route group.

##### Globally For Laravel 11

[](#globally-for-laravel-11)

Append the middleware to your default middlewares into your `bootstrap/app.php` via the code below to redirect all external traffic outside your designated host to your designated host.

```
->withMiddleware(function (Middleware $middleware) {
     $middleware->append(\ByteFlick\LaravelStrictDomain\Middlewares\RedirectExternalTraffic::class);
})
```

##### Globally For Laravel 10

[](#globally-for-laravel-10)

Add the middleware to your default middlewares into your `App\Http\Kernel.php` via the code below to redirect all external traffic outside your designated host to your designated host.

```
protected $middleware = [
    \ByteFlick\LaravelStrictDomain\Middlewares\RedirectExternalTraffic::class,
];
```

#### 2.2 Blocking External Traffic

[](#22-blocking-external-traffic)

If you want to block incoming traffic to your application from other domain/hosts to your own then you can use `BlockExternalTraffic` middleware. This is useful when you want to allow traffic from `janedoe.com` but block `johndoe.com` and others to your application.

##### On Specific Routes Only

[](#on-specific-routes-only-1)

You can add the middleware to individual routes or apply it via a route group.

##### Globally For Laravel 11

[](#globally-for-laravel-11-1)

Append the middleware to your default middlewares into your `bootstrap/app.php` via the code below to block all external traffic outside your designated host.

```
->withMiddleware(function (Middleware $middleware) {
     $middleware->append(\ByteFlick\LaravelStrictDomain\Middlewares\BlockExternalTraffic::class);
})
```

##### Globally For Laravel 10

[](#globally-for-laravel-10-1)

Add the middleware to your default middlewares into your `App\Http\Kernel.php` via the code below to block all external traffic outside your designated host.

```
protected $middleware = [
    \ByteFlick\LaravelStrictDomain\Middlewares\BlockExternalTraffic::class,
];
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [ByteFlick](https://github.com/ByteFlick)
- [ORPtech](https://orptech.com)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance60

Regular maintenance activity

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.6% 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

5

Last Release

785d ago

Major Versions

v1.0.0 → v2.0.02024-03-16

v2.0.1 → v3.0.02024-03-18

### Community

Maintainers

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

---

Top Contributors

[![ArdaKaraderi](https://avatars.githubusercontent.com/u/22325146?v=4)](https://github.com/ArdaKaraderi "ArdaKaraderi (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

checkcontroldomainlaravelmiddlewarephpredirectsecuritylaravelByteFlicklaravel-strict-domain

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/byteflick-laravel-strict-domain/health.svg)

```
[![Health](https://phpackages.com/badges/byteflick-laravel-strict-domain/health.svg)](https://phpackages.com/packages/byteflick-laravel-strict-domain)
```

###  Alternatives

[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

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