# Sporting Republic — Apache configuration (replaces the old WordPress .htaccess)

Options -Indexes
DirectoryIndex index.php
AddDefaultCharset UTF-8
ErrorDocument 404 /index.php?page=404

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# --- HTTPS ------------------------------------------------------------------------
# Left switched off on purpose: if a proxy/cache handles SSL in front of Apache,
# Apache never sees HTTPS and this rule would loop. Your host already serves https.
# RewriteCond %{HTTPS} off
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# --- Old WordPress: gone for good (410) ---------------------------------------
RewriteRule ^(wp-admin|wp-includes|wp-content)(/|$) - [G,L]
RewriteRule ^(wp-login|xmlrpc|wp-cron|wp-signup|wp-activate|wp-trackback|wp-comments-post|wp-mail|wp-links-opml|wp-load|wp-settings|wp-blog-header|wp-config)\.php$ - [G,L]
RewriteRule ^(readme\.html|license\.txt|index\.xhtml)$ - [G,L]
RewriteRule ^(.*/)?(feed|comments/feed|wp-json)(/.*)?$ - [G,L]
RewriteCond %{QUERY_STRING} (^|&)(attachment_id|p|page_id|rest_route|s)= [NC]
RewriteRule ^$ /? [L,R=301]

# --- Old WordPress URLs -> new pages (301) ------------------------------------
# The main pages keep their old addresses (/about-us/, /clients/, /our-team/, /contact-us/).
RewriteRule ^(about|events-projects)/?$ /about-us/ [L,R=301]
RewriteRule ^(home|news)/?$ / [L,R=301]
RewriteRule ^([0-9]{4}|category|tag|author)(/.*)?$ / [L,R=301]
RewriteRule ^(fonts|nc_assets|dup-installer|cgi-bin)(/|$) - [G,L]
RewriteRule ^(default\.htm|parking-page\.shtml|php_errorlog|wp-cli\.yml|\.litespeed_flag|[0-9A-F]{32}\.txt)$ - [G,L]
RewriteRule ^(sitemap_index|page-sitemap|post-sitemap|category-sitemap|author-sitemap)\.xml$ /sitemap.xml [L,R=301]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^robots\.txt$ robots.php [L]

# --- Languages not in use yet -> the English page (remove this rule when a language is switched back on)
RewriteRule ^(ja|ko|zh|vi)(/(.*))?$ /$3 [L,R=302]

# --- Never serve code or settings ----------------------------------------------
RewriteRule ^(inc|lang|data|lib|pages|private)(/|$) - [F,L]
RewriteRule (^|/)\. - [F,L]

# --- Pages: /, /menu/, /vi/, /vi/menu/ ... ---------------------------------------
# Add the trailing slash
RewriteRule ^((ja|ko|zh|vi)/)?(about-us|clients|our-team|contact-us)$ /$0/ [L,R=301]
RewriteRule ^(ja|ko|zh|vi)$ /$1/ [L,R=301]
RewriteRule ^(ja|ko|zh|vi)/?$ index.php?lang=$1&page=home [L,QSA]
RewriteRule ^(ja|ko|zh|vi)/(about-us|clients|our-team|contact-us)/$ index.php?lang=$1&page=$2 [L,QSA]
RewriteRule ^(about-us|clients|our-team|contact-us)/$ index.php?page=$1 [L,QSA]
RewriteRule ^$ index.php?page=home [L,QSA]

# Anything else that is not a real file -> friendly 404 page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php?page=404 [L,QSA]
</IfModule>

# --- Compression ------------------------------------------------------------------
<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript image/svg+xml application/xml text/plain application/json
</IfModule>
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript image/svg+xml application/xml text/plain application/json
</IfModule>

# --- Cache headers -------------------------------------------------------------------
# HTML pages set their own header in PHP: "public, max-age=60, s-maxage=600" (contact page: no-store).
<IfModule mod_headers.c>
  # CSS/JS are loaded with ?v=<timestamp>, so they can be cached for a year
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
    Header set Access-Control-Allow-Origin "*"
  </FilesMatch>
  # Photos: 30 days (give a new file name if you replace a photo)
  <FilesMatch "\.(webp|png|jpg|jpeg|svg|ico)$">
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>
  <FilesMatch "\.(pdf)$">
    Header set Cache-Control "public, max-age=604800"
  </FilesMatch>
  <FilesMatch "\.(xml|txt)$">
    Header set Cache-Control "public, max-age=3600"
  </FilesMatch>
  # Security headers
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

<IfModule mod_mime.c>
  AddType image/webp .webp
  AddType font/woff2 .woff2
  AddType application/pdf .pdf
</IfModule>
