mirror of
https://github.com/getgrav/grav.git
synced 2026-08-07 02:10:09 +02:00
Default to performing a 301 redirect for URIs with trailing slashes
This commit is contained in:
@@ -139,6 +139,17 @@ form:
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
pages.redirect_trailing_slash:
|
||||
type: toggle
|
||||
label: PLUGIN_ADMIN.REDIRECT_TRAILING_SLASH
|
||||
help: PLUGIN_ADMIN.REDIRECT_TRAILING_SLASH_HELP
|
||||
highlight: 1
|
||||
options:
|
||||
1: PLUGIN_ADMIN.YES
|
||||
0: PLUGIN_ADMIN.NO
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
languages:
|
||||
type: section
|
||||
title: PLUGIN_ADMIN.LANGUAGES
|
||||
|
||||
@@ -46,6 +46,7 @@ pages:
|
||||
etag: false # Set the etag header tag
|
||||
vary_accept_encoding: false # Add `Vary: Accept-Encoding` header
|
||||
redirect_default_route: false # Automatically redirect to a page's default route
|
||||
redirect_trailing_slash: true # Handle automatically or 301 redirect a trailing / URL
|
||||
|
||||
cache:
|
||||
enabled: true # Set to true to enable caching
|
||||
|
||||
@@ -31,7 +31,6 @@ class Uri
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$base = 'http://';
|
||||
$name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
|
||||
$port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
|
||||
@@ -80,6 +79,11 @@ class Uri
|
||||
$config = $grav['config'];
|
||||
$language = $grav['language'];
|
||||
|
||||
// If configured to, redirect trailing slash URI's with a 301 redirect
|
||||
if ($config->get('system.pages.redirect_trailing_slash', false) && $this->url != '/' && Utils::endsWith($this->url, '/')) {
|
||||
$grav->redirect(rtrim($this->url, '/'), 301);
|
||||
}
|
||||
|
||||
// resets
|
||||
$this->paths = [];
|
||||
$this->params = [];
|
||||
@@ -105,6 +109,7 @@ class Uri
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// split the URL and params
|
||||
$bits = parse_url($uri);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user