# Pearl Trails - top of the site folder.
# Laravel's web root is public/. Every request is passed into it, so the code,
# storage and .env next to this file can never be downloaded.
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On

    # SSL certificate checks and renewals must reach cPanel's files untouched
    RewriteRule ^\.well-known/ - [L]

    # One address per page: https, no www. Done here, BEFORE the rewrite into
    # public/, because LiteSpeed reports the rewritten /public/... path to rules
    # inside public/ and would redirect visitors to /public/about.
    RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} server404\.site$ [NC]
    RewriteRule ^(.*)$ https://server404.site/$1 [R=301,L]

    # /about/ -> /about
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [R=301,L]

    # Anyone typing /public/... gets the clean address
    RewriteCond %{THE_REQUEST} \s/public(/|\s|\?) [NC]
    RewriteRule ^public/?(.*)$ /$1 [R=301,L]

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

# Without mod_rewrite nothing here is served at all
<IfModule !mod_rewrite.c>
    Require all denied
</IfModule>
