jsefton/laravel-protocol

处理HTTP协议的检测以及更改内部链接和重定向

1.0.0 2020-04-06 08:53 UTC

This package is auto-updated.

Last update: 2024-09-06 19:14:14 UTC


README

处理HTTP协议的检测以及更改内部链接和重定向以匹配。

安装

您需要Composer来安装此包(获取Composer)。然后运行

composer require jsefton/laravel-protocol

注册服务提供者

将以下内容添加到您的 config/app.php 文件中的 providers 数组

JSefton\Protocol\ProtocolServiceProvider::class

安装完成后,您需要发布配置文件。为此请运行

php artisan vendor:publish --tag=protocol.config

这将创建一个 config/protocol.php 文件,您可以在此配置设置。

配置

auto

如果设置为true,这将自动将内部链接匹配到当前用户的协议。

protocol

如果设置,这将强制内部链接和重定向用户到设置的协议。接受的值是 httphttps。留空不设置。

environments

您可以在数组中添加自己的环境名称。数组的键应该匹配您使用的 APP_ENV 值,以便正确检测。

在每种环境中,您可以设置 httpstruefalse。如果为 true,则将更改所有内部链接为 https。如果将 redirect 设置为 true,则将强制所有用户使用 https,但前提是您已将 https 设置为 true

示例配置
/**
 * Automatically detect based on current protocol
 */
'auto' => false,

/**
 * Force everything to a set protocol either
 * 'http' or 'https'. If blank then won't 
 * force anything. Ignored if 'auto' is true.
 */
'protocol' => '',

/**
 * Use different rules per environment
 * Ignored if 'auto' is true or 'protocol' is set.
 */
'environments' => [
    'local' => [
        'https' => false,
        'redirect' => false
    ],
    'production' => [
        'https' => true,
        'redirect' => false
    ]
]