# ══════════════════════════════════════════════════════════════
#  FILE:  public_html/.htaccess
# ══════════════════════════════════════════════════════════════
Options -Indexes
RewriteEngine On

# ── RULE 1: Skip if actual file or directory exists on disk ───
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ── RULE 2: Never rewrite the router files themselves ─────────
RewriteRule ^journals/journal\.php   - [L]
RewriteRule ^journals/page\.php      - [L]

# ── RULE 3: Journal sub-page ──────────────────────────────────
#  /journals/social-science/aims-scope
#       → journals/page.php?journal=social-science&slug=aims-scope
#
RewriteRule ^journals/([a-z0-9-]+)/([a-z0-9-]+)/?$   journals/page.php?journal=$1&slug=$2   [L,QSA]

# ── RULE 4: Journal homepage ──────────────────────────────────
#  /journals/social-science
#  /journals/social-science/
#       → journals/journal.php?slug=social-science
#
RewriteRule ^journals/([a-z0-9-]+)/?$   journals/journal.php?slug=$1   [L,QSA]

# ── RULE 5: Strip .php extension ──────────────────────────────
#  /about-us  →  about-us.php  (also handles /page → /page.php)
#  Skips if the request already has an extension or is a directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)/?$   $1.php   [L,QSA]