Page 1 of 1

↪️ Page Redirects

Posted: Sat May 18, 2024 6:35 pm
by SpegalDev
Image

Navigating a website's evolution—whether updating page URLs, moving content, or transitioning to a secure HTTPS protocol—requires robust tools. The Redirect Plugin is designed to manage these changes efficiently, ensuring that your visitors and search engines can seamlessly transition with you.

Key Features
  • Maintaining SEO Value: When URLs change, the SEO value accumulated over time can be lost. Proper redirection preserves these values, passing on the benefits to the new URL.
  • Enhancing User Experience: Avoid the frustration associated with landing on outdated or broken links. Redirect users to the relevant content they are searching for without hassle.
  • Securing Your Site: Automatically redirect HTTP traffic to HTTPS, enhancing your website's security and trustworthiness.
Links
--------------------------------------------------------------------------------------------------------------------------------------------

If you use multiple BluditLab plugins, we highly recommend downloading our Update Checker. This handy tool will automatically ensure that all our plugins and themes remain up-to-date, helping you maintain a secure and fully functional website with ease.

Re: ↪️ Page Redirects

Posted: Sat Dec 27, 2025 4:30 pm
by dlombardo
Hi, I have problems with activation of the plugin.

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".

If I install some other plugin the same way e.g. yours https://bluditlab.com/plugins/media/youtube-embed, I have no issues activating.

Re: ↪️ Page Redirects

Posted: Sat Dec 27, 2025 4:51 pm
by dlombardo
Hi,

I guess I can use this plugin to have a redirect URL on my Bludit website to be redirected to external website.

Example, if I create a redirect URL that redirects to Facebook URL and then I use redirect URL in QR code, the QR code should open Facebook URL using this redirect.
Like your demo URL: https://demo.bluditlab.com/plugin/page- ... ulla-augue opens the google.

Are page-redirects handled in statistics in bludit e.g. using Simple-Stats-Plus plugin?
Is there another 'per page' stats plugin that counts also redirects?
The Simple-Stats-Plkus plugin does not work on Bludit 3.16.2 :(.

Re: ↪️ Page Redirects

Posted: Sat Dec 27, 2025 8:14 pm
by Edi
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.