# -----------------------------------------------------------------------
# @author     Akshari Solutions
# @copyright  (c) 2026 Akshari Solutions. All rights reserved.
# -----------------------------------------------------------------------
#
# Laravel front controller for the public/ folder (the web root).
# Do not add a cPanel "AddHandler" PHP block by hand: choose PHP 8.4 in
# cPanel > MultiPHP Manager and cPanel writes the right handler itself.

<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Live domain only: send http:// and the bare domain to
    # https://www.yyczonedrivingacademy.com (one canonical address for SEO).
    # Only on the original request (REDIRECT_STATUS empty), never on Apache's
    # internal passes; Let's Encrypt / AutoSSL checks under /.well-known stay
    # reachable over plain http.
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_URI} !^/\.well-known/ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?yyczonedrivingacademy\.com$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP:X-Forwarded-Proto} !=https
    RewriteRule ^(.*)$ https://www.yyczonedrivingacademy.com/$1 [R=301,L,NE]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_URI} !^/\.well-known/ [NC]
    RewriteCond %{HTTP_HOST} ^yyczonedrivingacademy\.com$ [NC]
    RewriteRule ^(.*)$ https://www.yyczonedrivingacademy.com/$1 [R=301,L,NE]

    # The Laravel 7 site was served from the project root, so its asset URLs
    # started with /public/ (images on Google still use them). Redirect them
    # to the same file without the prefix. The optional group covers both
    # set-ups: document root = public/ (path still has "public/") and the
    # project-root fallback (prefix already stripped by the root .htaccess).
    RewriteCond %{THE_REQUEST} \s/+public/ [NC]
    RewriteRule ^(?:public/)?(.*)$ /$1 [R=301,L,NE]

    # Hidden files and folders (.env, .git, .htaccess) are never served,
    # except the SSL validation folder.
    RewriteRule (^|/)\.(?!well-known/) - [F,L]

    # Only index.php may run as a script; any other script name is refused,
    # including the /file.php/extra-path form.
    RewriteRule ^(?!index\.php$).*\.(php[0-9]?|phtml|phar|pht|cgi|pl|shtml?)(\.|/|$) - [F,L,NC]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder... (built from the path, not
    # REQUEST_URI, so the project-root fallback never leaks "/public" into it)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# Browser caching for theme assets (they rarely change).
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 30 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/x-icon "access plus 30 days"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType text/css "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"
    ExpiresByType text/javascript "access plus 7 days"
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/javascript text/javascript image/svg+xml
</IfModule>
