Skip to content

Commit

Permalink
Merge branch 'feature/keep_querystring' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
sander-beenen committed Nov 30, 2023
2 parents 3c81f7c + 1588474 commit 913a4d5
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions classes/PublishManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function publish(): int
'ignore_query_parameters',
'ignore_case',
'ignore_trailing_slash',
'keep_querystring',
];

/** @var Collection $redirects */
Expand Down
8 changes: 8 additions & 0 deletions classes/RedirectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public function redirectWithRule(RedirectRule $rule, string $requestUri): void
return;
}

if ($rule->isKeepQuerystring()) {
$parsedUrl = parse_url($requestUri);

if (isset($parsedUrl['query'])) {
$toUrl .= '?' . $parsedUrl['query'];
}
}

$this->addLogEntry($rule, $requestUri, $toUrl);

header(self::$headers[$statusCode], true, $statusCode);
Expand Down
12 changes: 12 additions & 0 deletions classes/RedirectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class RedirectRule
private bool $ignoreQueryParameters;
private bool $ignoreCase;
private bool $ignoreTrailingSlash;
private bool $keepQuerystring;

public function __construct(array $attributes)
{
Expand Down Expand Up @@ -92,6 +93,12 @@ public function __construct(array $attributes)
}
}

if ($attributes['ignore_query_parameters'] === false) {
$this->keepQuerystring = false;
} else {
$this->keepQuerystring = (bool) ($attributes['keep_querystring'] ?? false);
}

$this->ignoreQueryParameters = (bool) ($attributes['ignore_query_parameters'] ?? false);
$this->ignoreCase = (bool) ($attributes['ignore_case'] ?? false);
$this->ignoreTrailingSlash = (bool) ($attributes['ignore_trailing_slash'] ?? false);
Expand Down Expand Up @@ -234,4 +241,9 @@ public function isIgnoreTrailingSlash(): bool
{
return $this->ignoreTrailingSlash;
}

public function isKeepQuerystring(): bool
{
return $this->keepQuerystring;
}
}
2 changes: 2 additions & 0 deletions lang/de/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
'ignore_case_comment' => 'Gross-/Kleinschreibung wird für die Weiterleitung nicht beachtet.',
'ignore_trailing_slash' => 'Schrägstrich am Ende ignorieren',
'ignore_trailing_slash_comment' => 'Pfade mit und ohne Schrägstrich am Schluss werden umgeleitet.',
'keep_querystring' => 'Abfragezeichenfolge erben',
'keep_querystring_comment' => 'Eventuell vorhandene Abfrageparameter werden an den Zielpfad bzw. die Ziel-URL übergeben.',
'last_used_at' => 'Letzter Treffer',
'updated_at' => 'Aktualisiert',
'invalid_regex' => 'Ungültiger Regulärer Ausdruck.',
Expand Down
2 changes: 2 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
'ignore_case_comment' => 'The redirect engine will do case-insensitive matching.',
'ignore_trailing_slash' => 'Ignore trailing slash',
'ignore_trailing_slash_comment' => 'The redirect engine will ignore trailing slashes.',
'keep_querystring' => 'Inherit querystring',
'keep_querystring_comment' => 'Any query parameters present are passed to the target path or URL.',
'last_used_at' => 'Last hit',
'updated_at' => 'Updated at',
'invalid_regex' => 'Invalid regular expression.',
Expand Down
2 changes: 2 additions & 0 deletions lang/es/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
'ignore_case_comment' => 'El motor de redirección hará coincidir las mayúsculas y minúsculas.',
'ignore_trailing_slash' => 'Ignoren la barra de arrastre',
'ignore_trailing_slash_comment' => 'El motor de redireccionamiento ignorará las barras de arrastre.',
'keep_querystring' => 'Heredar cadena de consulta',
'keep_querystring_comment' => 'Todos los parámetros de consulta presentes se pasan a la ruta o URL de destino.',
'last_used_at' => 'Último resultado',
'updated_at' => 'Actualizado en',
'invalid_regex' => 'Expresión regular inválida.',
Expand Down
2 changes: 2 additions & 0 deletions lang/fr/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
'ignore_case_comment' => 'The redirect engine will do case-insensitive matching.', // TODO
'ignore_trailing_slash' => 'Ignore trailing slash', // TODO
'ignore_trailing_slash_comment' => 'The redirect engine will ignore trailing slashes.', // TODO
'keep_querystring' => 'Hériter de la chaîne de requête',
'keep_querystring_comment' => 'Tous les paramètres de requête présents sont transmis au chemin ou à l\'URL cible.',
'last_used_at' => 'Last hit', // TODO
'updated_at' => 'Updated at', // TODO
'invalid_regex' => 'Invalid regular expression.', // TODO
Expand Down
2 changes: 2 additions & 0 deletions lang/nl/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
'ignore_case_comment' => 'Het matching-algoritme is niet hoofdlettergevoelig.',
'ignore_trailing_slash' => 'Negeer slashes aan het einde van het bronpad.',
'ignore_trailing_slash_comment' => '',
'keep_querystring' => 'Neem querystring over',
'keep_querystring_comment' => 'Aanwezige query parameters worden meegegeven aan het doelpad of URL.',
'last_used_at' => 'Laatste treffer',
'updated_at' => 'Bijgewerkt op',
'invalid_regex' => 'Ongeldige reguliere expressie.',
Expand Down
2 changes: 2 additions & 0 deletions lang/ru/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
'ignore_case_comment' => 'Дивжок редиректов будет работать без учета регистра.',
'ignore_trailing_slash' => 'Игнорировать завершающий слэш',
'ignore_trailing_slash_comment' => 'Дивжок редиректов будет игнорировать завершающий слэш.',
'keep_querystring' => 'наследовать строку запроса',
'keep_querystring_comment' => 'Любые имеющиеся параметры запроса передаются по целевому пути или URL-адресу.',
'last_used_at' => 'Последний хит',
'updated_at' => 'Обновлено',
'invalid_regex' => 'Неправильное регулярное выражение.',
Expand Down
2 changes: 2 additions & 0 deletions lang/sv/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
'ignore_case_comment' => 'The redirect engine will do case-insensitive matching.', // TODO
'ignore_trailing_slash' => 'Ignore trailing slash', // TODO
'ignore_trailing_slash_comment' => 'The redirect engine will ignore trailing slashes.', // TODO
'keep_querystring' => 'Ärv frågesträng',
'keep_querystring_comment' => 'Alla frågeparametrar som finns skickas till målsökvägen eller webbadressen.',
'last_used_at' => 'Användes senast',
'updated_at' => 'Updated at', // TODO
'invalid_regex' => 'Invalid regular expression.', // TODO
Expand Down
1 change: 1 addition & 0 deletions models/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ final class Redirect extends Model
'is_enabled' => 'boolean',
'test_lab' => 'boolean',
'system' => 'boolean',
'keep_querystring' => 'boolean',
];

protected static function makeValidator(
Expand Down
11 changes: 11 additions & 0 deletions models/redirect/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ tabs:
span: left
default: false
comment: vdlp.redirect::lang.redirect.ignore_query_parameters_comment
keep_querystring:
label: vdlp.redirect::lang.redirect.keep_querystring
type: checkbox
span: left
cssClass: field-indent
default: false
trigger:
action: show
field: ignore_query_parameters
condition: checked
comment: vdlp.redirect::lang.redirect.keep_querystring_comment
description:
label: vdlp.redirect::lang.redirect.description
span: right
Expand Down
31 changes: 31 additions & 0 deletions updates/20231108_0013_add_keep_querystring_to_redirects_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;

class AddKeepQueryStringToRedirectsTable extends Migration
{
public function up(): void
{
if (Schema::hasColumn('vdlp_redirect_redirects', 'keep_querystring')) {
return;
}

Schema::table('vdlp_redirect_redirects', static function (Blueprint $table): void {
$table->boolean('keep_querystring')
->default(false)
->after('ignore_trailing_slash');
});
}

public function down(): void
{
if (Schema::hasColumn('vdlp_redirect_redirects', 'keep_querystring')) {
Schema::table('vdlp_redirect_redirects', static function (Blueprint $table): void {
$table->dropColumn('keep_querystring');
});
}
}
}
3 changes: 3 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ v3.1.7: "Remove use of old BrandSetting constants."
v3.1.8: "Add German translation."
v3.1.9: "Added environment variables for manipulating the navigation."
v3.1.10: "Fixed backend filtering for MySQL >= 8.0.3."
v3.1.11:
- "Added feature to keep the querystring when redirecting"
- 20231108_0013_add_keep_querystring_to_redirects_table.php

0 comments on commit 913a4d5

Please sign in to comment.