ServerName localhost

# === LOGGING ===
LogFormat "%a %{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Host}i\"" fullinfo
CustomLog /proc/self/fd/1 fullinfo
ErrorLog /proc/self/fd/2
LogLevel warn

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

        <IfModule rewrite_module>
            RewriteEngine On

            # === Block bad bots ===
            RewriteCond %{HTTP_USER_AGENT} "python-requests" [NC,OR]
            RewriteCond %{HTTP_USER_AGENT} "python" [NC]
            RewriteRule .* - [F,L]

            # === Laravel routing (fallback to index.php) ===
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^ index.php [L]
        </IfModule>
    </Directory>

    # === SECURITY: BLOCK SENSITIVE FILES ===

    # Deny access to any .git directories
    <DirectoryMatch "^/.*/\.git">
        Require all denied
    </DirectoryMatch>

    # Block .env file specifically
    <Files ".env">
        Require all denied
    </Files>

    # Deny access to all dotfiles (.git, .htaccess, etc.)
    <FilesMatch "^\.">
        Require all denied
    </FilesMatch>

</VirtualHost>
