# Apache config for MediaWiki pretty URLs: /wiki/Article_Name
# Place this file in the same directory as index.php (your MediaWiki root).
# Requires mod_rewrite to be enabled: a2enmod rewrite

Options -Indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # ------------------------------------------------------------------
    # Block direct access to sensitive files
    # ------------------------------------------------------------------
    RewriteRule ^LocalSettings\.php$   - [F,L]
    RewriteRule ^composer\.(json|lock) - [F,L]
    RewriteRule ^\.env                 - [F,L]
    RewriteRule ^data/                 - [F,L]
    RewriteRule ^cache/                - [F,L]

    # ------------------------------------------------------------------
    # Pretty URLs: /wiki/Article -> index.php?title=Article&...
    # ------------------------------------------------------------------
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteCond %{REQUEST_URI} !^/resources/
    RewriteCond %{REQUEST_URI} !^/skins/
    RewriteCond %{REQUEST_URI} !^/extensions/
    RewriteCond %{REQUEST_URI} !^/load\.php
    RewriteCond %{REQUEST_URI} !^/api\.php
    RewriteCond %{REQUEST_URI} !^/rest\.php
    RewriteCond %{REQUEST_URI} !^/index\.php
    RewriteRule ^wiki/(.*)$    index.php?title=$1 [L,QSA]

    # Redirect bare / to the main page
    RewriteRule ^$             index.php [L,QSA]
</IfModule>

# ------------------------------------------------------------------
# Security headers
# ------------------------------------------------------------------
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ------------------------------------------------------------------
# Compression (speeds up page loads significantly)
# ------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml
    AddOutputFilterByType DEFLATE text/css application/javascript application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# ------------------------------------------------------------------
# Browser caching for static assets
# ------------------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/png  "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif  "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 week"
    ExpiresByType text/css          "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>
