dlombardo wrote: Sat Dec 27, 2025 4:30 pm
When I upload and extract the plugin .zip to bl-plugins the plugin shows in Bludit admin page plugins, but then when I click "Activate" the link .../install-plugin/pluginRedirectPages return with "500 internal server error".
The plugin does not work with PHP 8.
I asked ChatGPT to update it. He gave me the following code for the file plugin.php:
Code: Select all
<?php
class pluginRedirectPages extends Plugin
{
public function init()
{
// Standardwerte
$this->dbFields = [
'force-https' => false,
'https-status' => 301,
'allow-external' => false,
'redirects' => '' // JSON-String
];
}
/* ===============================
FRONTEND REDIRECT
=============================== */
public function beforeAll()
{
global $url;
$redirectsJson = $this->getValue('redirects');
$redirects = json_decode($redirectsJson, true);
if (!is_array($redirects)) {
return; // keine Redirects
}
$slug = trim($url->slug(), '/');
if (!isset($redirects[$slug])) {
return; // kein Redirect für diese Seite
}
$rule = $redirects[$slug];
// Ziel-URL formen
$target = $this->formRedirectUrl($rule['to'] ?? '', (bool)$this->getValue('allow-external'));
if (!$target) {
return; // ungültiges Ziel
}
$status = ((int)($rule['status'] ?? $this->getValue('https-status')) === 301) ? 301 : 302;
// Optional HTTPS erzwingen
if ($this->getValue('force-https') && strpos($target, 'http://') === 0) {
$target = 'https://' . substr($target, 7);
}
if (!empty($_GET)) {
$target .= '?' . http_build_query($_GET);
}
header("Location: $target", true, $status);
exit;
}
private function formRedirectUrl(string $to, bool $allowExternal): ?string
{
$to = trim($to);
if ($to === '') {
return null;
}
if ($allowExternal && (strpos($to, 'http://') === 0 || strpos($to, 'https://') === 0)) {
return $to;
}
return rtrim(DOMAIN_BASE, '/') . '/' . ltrim($to, '/');
}
/* ===============================
ADMIN FORM
=============================== */
public function form()
{
$redirects = $this->getValue('redirects');
if (!is_string($redirects)) {
$redirects = '';
}
?>
<h3>Redirect Settings</h3>
<div class="form-group">
<label>
<input type="hidden" name="force-https" value="false">
<input type="checkbox" name="force-https" value="true"
<?php echo $this->getValue('force-https') ? 'checked' : ''; ?>>
Force HTTPS Everywhere
</label>
</div>
<div class="form-group">
<label>Default Redirect Status</label>
<select name="https-status" class="form-control">
<option value="301" <?php echo $this->getValue('https-status') == 301 ? 'selected' : ''; ?>>301 - Moved Permanently</option>
<option value="302" <?php echo $this->getValue('https-status') == 302 ? 'selected' : ''; ?>>302 - Moved Temporarily</option>
</select>
</div>
<div class="form-group">
<label>
<input type="hidden" name="allow-external" value="false">
<input type="checkbox" name="allow-external" value="true"
<?php echo $this->getValue('allow-external') ? 'checked' : ''; ?>>
Allow External Redirects
</label>
</div>
<hr>
<h3>Redirect Rules (JSON)</h3>
<p>Format:</p>
<pre>{
"old-slug": {"to":"new-slug-or-URL","status":301}
}</pre>
<textarea name="redirects" rows="12" class="form-control"><?php echo htmlspecialchars($redirects); ?></textarea>
<?php
}
/* ===============================
SAVE POST DATA
=============================== */
public function post()
{
$this->db['force-https'] = ($_POST['force-https'] ?? 'false') === 'true';
$this->db['https-status'] = (int)($_POST['https-status'] ?? 301);
$this->db['allow-external'] = ($_POST['allow-external'] ?? 'false') === 'true';
$json = $_POST['redirects'] ?? '';
$decoded = json_decode($json, true);
if (!is_array($decoded)) {
return false; // ungültiges JSON
}
$this->db['redirects'] = json_encode($decoded, JSON_UNESCAPED_SLASHES);
return $this->save();
}
/* ===============================
ADMIN SIDEBAR
=============================== */
public function adminSidebar()
{
return '<a class="nav-link" href="' . HTML_PATH_ADMIN_ROOT . 'configure-plugin/pluginRedirectPages">Redirects</a>';
}
}
The chat is at
https://chatgpt.com/share/69502fc5-8064 ... eafc07b266
I will inform the developer.