# Custom URL routing configuration
<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    
    # Enable compression for text files
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
    </IfModule>
    
    # Set caching headers for static assets
    <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js|css|svg)$">
        Header set Cache-Control "max-age=86400, public"
    </FilesMatch>
    
    # Block access to .md files
    <Files ~ "\.md$">
        Require all denied
    </Files>
    
    # Enable .html extension to be optional
    <IfModule mod_rewrite.c>
        RewriteEngine On
        
        # Don't apply to existing files or directories
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        
        # Check if the .html version exists
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
        
        # Internally rewrite to the .html version
        RewriteRule ^ %{REQUEST_URI}.html [L]
        
        # Remove .html extension from direct requests
        RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
        RewriteRule ^ /%1 [R=301,L,NE]
        
        # Special route for /fumo to show fumo.jpg
        RewriteRule ^fumo/?$ /blog/images/fumo.jpg [L]
    </IfModule>
</Directory>

# Alias for /blog to serve from the blog directory
Alias "/blog" "/var/www/html/blog"

# Configure DirectoryIndex for both root and blog directory
<LocationMatch "^/$">
    DirectoryIndex index.html
</LocationMatch>

<LocationMatch "^/blog/?$">
    DirectoryIndex index.html
</LocationMatch>

# Custom error pages
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
