https://github.com/ymigval/laravel-wwwprotocolresolver
Redirect with or without www. and from http to https in Laravel.
https://github.com/ymigval/laravel-wwwprotocolresolver
http https laravel protocol redirect seo-optimization www
Last synced: 11 months ago
JSON representation
Redirect with or without www. and from http to https in Laravel.
- Host: GitHub
- URL: https://github.com/ymigval/laravel-wwwprotocolresolver
- Owner: ymigval
- License: mit
- Created: 2024-01-21T12:27:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-26T19:18:23.000Z (over 1 year ago)
- Last Synced: 2025-05-30T14:35:54.295Z (about 1 year ago)
- Topics: http, https, laravel, protocol, redirect, seo-optimization, www
- Language: PHP
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel WWW Protocol Resolver
The "laravel-wwwprotocolresolver" package provides easy configuration for redirecting responses with or without "www" and with the specified protocol (http or https) in Laravel applications. You can customize the redirection type (permanent or temporary), scheme (http or https), and redirection mode (with or without "www") according to your needs.
## Installation
To install the package, run the following command in your Laravel project's terminal:
```bash
composer require ymigval/laravel-wwwprotocolresolver
```
## Publish configuration file (optional)
If you want to customize the package configuration, you can publish the configuration file using the following command:
```bash
php artisan vendor:publish --tag="wwwprotocolresolver"
```
## Usage
To use the package, simply add the following environment variables to your .env file:
```dotenv
# Supported: "http", "https"
WWW_PROTOCOL_RESOLVER_USE=https
# Supported: "with_www", "without_www"
WWW_PROTOCOL_RESOLVER_MODE=with_www
```
Ensure that you set these configurations only in production environments to avoid unwanted redirections during development.
### Configuration
You can adjust the package configuration in the `config/wwwprotocolresolver.php` file. Here, you can define the redirection type (301 or 302), scheme (http or https), and redirection mode (with or without "www") according to your preferences.
```php
return [
'type' => env('WWW_PROTOCOL_RESOLVER_TYPE', 301),
'use' => env('WWW_PROTOCOL_RESOLVER_USE'),
'mode' => env('WWW_PROTOCOL_RESOLVER_MODE'),
];
```
This package allows you to enhance the security and consistency of your URLs by ensuring that all users are redirected to the preferred version of your website.
## Changelog
Please refer to the [CHANGELOG](CHANGELOG.md) for more information about recent changes.
## License
The MIT License (MIT). For more information, please see the [License File](LICENSE).