Jump to content

ICT:Clean URLs for MW 1.45

From Costa Sano MediaWiki
Revision as of 16:30, 11 April 2026 by Mngr (talk | contribs) (Created page with "== MediaWiki 1.45.2 Clean URL Configuration for kb.costasano.club == This document outlines the "Short URL" configuration for the wiki migration to version 1.45.2 on AlmaLinux 10. === Architecture Overview === * **Domain:** <code>https://costasano.club</code> * **Frontend (Reverse Proxy):** Nginx on AlmaLinux 10 (Handling SSL/HTTPS). * **Backend (Web Server):** Apache on AlmaLinux 10 (Handling PHP/MediaWiki). * **Document Root:** <code>/var/www/mw145</code> (index.php...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

MediaWiki 1.45.2 Clean URL Configuration for kb.costasano.club

This document outlines the "Short URL" configuration for the wiki migration to version 1.45.2 on AlmaLinux 10.

Architecture Overview

  • **Domain:** https://costasano.club
  • **Frontend (Reverse Proxy):** Nginx on AlmaLinux 10 (Handling SSL/HTTPS).
  • **Backend (Web Server):** Apache on AlmaLinux 10 (Handling PHP/MediaWiki).
  • **Document Root:** /var/www/mw145 (index.php is located here).
  • **URL Strategy:** Using the /wiki/ virtual prefix to simplify the Apache configuration and avoid the complex "exclusion lists" used in version 1.43.

Step 1: Nginx Proxy Configuration (The Bridge)

The Nginx proxy is configured as a "transparent bridge." It does not handle rewrites; it simply passes the /wiki/ path through to the Apache backend.

server {
    listen 443 ssl;
    server_name kb.costasano.club;

    # SSL Certs (Managed at Nginx layer)
    ssl_certificate /etc/letsencrypt/live/kb.costasano.club/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/kb.costasano.club/privkey.pem;

    location / {
        proxy_pass http://[BACKEND_IP_OR_HOSTNAME];
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https; # Tells MediaWiki the user is on HTTPS
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Step 2: Apache Configuration (The Logic)

Apache handles the translation of the "clean" URL into a format PHP understands.

2.1 Enable Overrides

Ensure /etc/httpd/conf/httpd.conf (or your specific Vhost file) allows the .htaccess file to function:

<Directory "/var/www/mw145">
    AllowOverride All
    Require all granted
</Directory>

2.2 Create .htaccess

Place this file at /var/www/mw145/.htaccess. It maps the virtual /wiki/ path to the physical index.php.

RewriteEngine On

# 1. Map the virtual /wiki/ path to index.php
RewriteRule ^wiki/(.*)$ /index.php?title=$1 [PT,L,QSA]

# 2. Redirect root domain (kb.costasano.club/) to the Main Page
RewriteRule ^$ /wiki/ [R,L]

Step 3: MediaWiki LocalSettings.php

Update /var/www/mw145/LocalSettings.php to define the identity of the wiki and trust the Nginx header.

## URL Settings
$wgServer = "https://costasano.club";
$wgScriptPath = "";         // Files are directly in /var/www/mw145
$wgArticlePath = "/wiki/$1"; // Users see this path

## Reverse Proxy / HTTPS Handling
# Ensures MediaWiki knows it is served over HTTPS even if Apache is HTTP
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

# Trust the internal IP of your Nginx Proxy
$wgUsePrivateIPs = true;
$wgCdnServersNoPurge = [ '127.0.0.1', '[IP_OF_NGINX_PROXY]' ];

Why we use the "/wiki/" prefix

  • Simplicity: Unlike the version 1.43 setup, we no longer need a massive list of exclusions (RewriteCond) for every folder (skins, images, resources, etc.).
  • Stability: It prevents "Path Collisions" where a wiki page name might conflict with a real folder on the disk.
  • Performance: Reduces the processing load on Apache for every request.