Patrol plugin for Craft CMS
Easy Maintenance Mode and Smart HTTPS Routing., (*1)
Features
HTTPS Routing 👮
- Force HTTPS (server agnostic)
- Force a Primary Domain (naked domain vs www prefixed)
- Define where HTTPS is enforced (if not globally)
- Control the best redirect status code for your use case
Maintenance Mode 🚧
- Put your site on maintenance mode
- Define who can access the site while offline
- Reroute guests to an offline page (or custom response)
Installation
You can install Patrol via the plugin store, or through Composer., (*2)
Craft Plugin Store
To install Patrol, navigate to the Plugin Store section of your Craft control panel, search for Patrol
, and click the Try button., (*3)
Composer
You can also add the package to your project using Composer., (*4)
-
Open your terminal and go to your Craft project:, (*5)
cd /path/to/project
-
Then tell Composer to load the plugin:, (*6)
composer require verbb/patrol
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Patrol., (*7)
Configuring Patrol
The plugin is configured in the config/
directory in a file you create called patrol.php
. What follows is an example of what it might contain., (*8)
return [
'*' => [
'primaryDomain' => null,
'redirectStatusCode' => 302,
'sslRoutingBaseUrl' => "https://mysecuredwebsite.com",
'sslRoutingEnabled' => true,
'sslRoutingRestrictedUrls' => ['/'],
'maintenanceModeEnabled' => false,
'maintenanceModePageUrl' => '/offline',
'maintenanceModeAuthorizedIps' => ['::1', '127.0.0.1'],
'maintenanceModeResponseStatusCode' => 410,
],
'dev' => [
'sslRoutingEnabled' => false,
]
'staging' => [
'maintenanceModePageUrl' => null,
'maintenanceModeResponseStatusCode' => 410,
],
'production' => [
'redirectStatusCode' => 301,
'maintenanceModeResponseStatusCode' => 503,
]
];
Configuration Options
-
primaryDomain
- Primary domain to enforce.
-
redirectStatusCode
- Redirect status code to use when redirecting.
-
sslRoutingBaseUrl
- Tells Patrol what base URL to use when redirecting to SSL.
-
sslRoutingEnabled
- Tells Patrol to force requests to be made over https://
.
-
sslRoutingRestrictedUrls
- Tells Patrol where https://
should be enforced.
-
maintenanceModeEnabled
- Tells Patrol that your site is on maintenance mode and it should start routing traffic differently. Authorized users will see your site while unauthorized users will see either your offline page or an HTTP response with a custom status code.
-
maintenanceModeAuthorizedIps
- IP addresses that should be allowed (without being logged in) during maintenance.
-
maintenanceModeResponseStatusCode
- Tells Patrol what kind of HttpException
to throw if you do not set a $maintenanceModePageUrl
.
-
maintenanceModeAccessTokens
- Access tokens that can be used to automatically add an IP to the allowed list.
Access Tokens
If you define the following access tokens:, (*9)
$maintenanceModeAccessTokens = [
'ceo-access-token',
'd0nn3bd8a2iza1ikjxxdo28iicabh7ts',
];
You will be able to send someone a link with the access token. When the visit that link, their IP will be added to the allowed list., (*10)
- https://domain.com/?access=ceo-access-token
- https://domain.com/?access=d0nn3bd8a2iza1ikjxxdo28iicabh7ts
You can use any string as an access token but avoid using spaces., (*11)
If you are planning on using access tokens, do not include $maintenanceModeAuthorizedIps
as a file config setting., (*12)
Credits
Originally created by Selvin Ortiz., (*13)
Show your Support
Patrol is licensed under the MIT license, meaning it will always be free and open source – we love free stuff! If you'd like to show your support to the plugin regardless, Sponsor development., (*14)
, (*15)