# public_html/auth/.htaccess
# Clean URLs for /auth
# Examples:
#   /auth                -> /auth/login
#   /auth/login          -> /auth/login.php
#   /auth/logout         -> /auth/logout.php
#   /auth/login/logged_out -> /auth/login.php?e=logged_out

Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /auth/

    # -------------------------------------------------
    # 1) Default route: /auth -> /auth/login
    # -------------------------------------------------
    RewriteRule ^$ login.php [L]

    # -------------------------------------------------
    # 2) Redirect /auth/page.php -> /auth/page
    # -------------------------------------------------
    RewriteCond %{THE_REQUEST} \s/+auth/([^\s?]+)\.php(?:[\s?]|$) [NC]
    RewriteRule ^ %1 [R=301,L]

    # -------------------------------------------------
    # 3) Clean login status URL
    #    /auth/login/logged_out -> /auth/login.php?e=logged_out
    #    /auth/login/session_expired -> /auth/login.php?e=session_expired
    # -------------------------------------------------
    RewriteRule ^login/([^/]+)/?$ login.php?e=$1 [L,QSA,NC]

    # -------------------------------------------------
    # 4) Do not rewrite real files or directories
    # -------------------------------------------------
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # -------------------------------------------------
    # 5) Internally map /auth/page -> /auth/page.php
    # -------------------------------------------------
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.php [L,NC]
</IfModule>