# 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
    <IfModule mod_headers.c>
        <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|js|css|svg)$">
            Header set Cache-Control "max-age=86400, public"
        </FilesMatch>
    </IfModule>
    
    # Configure dotfiles with proper MIME type
    <Files "vimrc">
        ForceType text/plain
    </Files>
    
    <Files "dotfiles.sh">
        ForceType text/plain
    </Files>
    
    <IfModule mod_headers.c>
        <Files "vimrc">
            Header set Cache-Control "max-age=3600, public"
        </Files>
        
        <Files "dotfiles.sh">
            Header set Cache-Control "max-age=3600, public"
        </Files>
    </IfModule>
    
    # Block access to .md files
    <Files ~ "\.md$">
        Require all denied
    </Files>
    
    # Enable .html extension to be optional
    <IfModule mod_rewrite.c>
        RewriteEngine On
        
        # Special route for /fumo to show fumo.jpg
        RewriteRule ^fumo/?$ /blog/images/fumo.jpg [L]
        
        # 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]
    </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
