parallax/laravel-protocol

处理HTTP协议检测,并更改内部链接和重定向

dev-master 2018-03-01 18:15 UTC

This package is auto-updated.

Last update: 2024-09-18 01:48:36 UTC


README

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

安装

您需要使用composer安装此包(获取composer)。然后运行

composer require parallax/laravel-protocol

注册服务提供者

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

Parallax\Protocol\ProtocolServiceProvider::class

安装后,您需要发布配置文件。要执行此操作,请运行

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

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

配置

auto

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

protocol

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

environments

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

在每种环境中,您可以设置 httpstruefalse。如果设置为 true,这将更改所有内部链接到 https。如果您设置 redirecttrue,那么这将强制所有用户使用 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
    ]
]