# ============================================================
# B2B Cloths - Shared Hosting Root Redirect
#
# USE WHEN: document root = this folder (e.g. public_html/)
# so that the domain serves directly WITHOUT changing
# document root to /public.
#
# What it does:
#   - domain.com/          -> serves public/index.php
#   - domain.com/install.php -> serves public/install.php
#   - domain.com/admin/... -> serves public/admin/...
#
# If your host already points document root to the /public
# folder, this file is simply ignored by Apache.
# ============================================================

<IfModule mod_rewrite.c>
    RewriteEngine On

    # If a file or directory actually exists, serve it directly
    # (e.g. .env.example, favicon, robots.txt at root)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Allow direct access to the installer UI at the domain root
    RewriteRule ^install\.php$ public/install.php [L]

    # Prevent infinite loop: if already inside /public, stop
    RewriteRule ^public/ - [L]

    # Forward everything else into the public/ folder
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

# Security: block direct access to sensitive root files
<FilesMatch "^(\.env|\.env\.example|artisan|composer\.json|composer\.lock|package\.json|package-lock\.json|vite\.config\.js|phpunit\.xml)$">
    Require all denied
</FilesMatch>

# Block directory browsing
Options -Indexes
