# BBSEngine Documentation/Handbook Apache Configuration
# Place this file in /etc/apache2/sites-available/ or /etc/apache2/conf-available/
# Then enable with: a2ensite bbsengine-handbook.conf
# Or include with: Include /path/to/bbsengine6/handbook/bbsengine-handbook.conf

# Handbook directory alias
Alias /handbook/ "/home/opencode/data/work/bbsengine6/handbook/"

<Directory "/home/opencode/data/work/bbsengine6/handbook/">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted

    # Enable module requirements
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /handbook/

        # Serve index.html for directory requests
        DirectoryIndex index.html index.md README.md

        # Block access to backup files
        RewriteRule ^.*\.(md~|bak|swp|swo)$ - [F,L]

        # Block hidden files
        RewriteRule "^\." - [F,L]
    </IfModule>

    # Proper MIME types
    <IfModule mod_mime.c>
        AddType text/markdown .md
        AddType text/plain .txt
        AddType text/html .html
        AddEncoding gzip .gz
    </IfModule>

    # Set content headers for markdown files
    <FilesMatch "\.md$">
        Header set Content-Type "text/markdown; charset=utf-8"
        Header set Content-Disposition "inline"
    </FilesMatch>

    # Gzip compression for text files
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/markdown text/plain text/html text/xml application/json text/javascript
    </IfModule>

    # Cache control
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 1 week"
        ExpiresByType text/markdown "access plus 7 days"
        ExpiresByType text/html "access plus 7 days"
        ExpiresByType text/plain "access plus 7 days"
    </IfModule>

    # Directory listing styling
    <IfModule mod_autoindex.c>
        IndexOptions NameWidth=* VersionSort HTMLTable FancyIndexing Charset=UTF-8
        HeaderName HEADER.html
        ReadmeName FOOTER.html
        AddIconByType (TXT,/icons/text.gif) text/*
        AddIconByType (IMG,/icons/image2.gif) image/*
        AddIcon /icons/folder.gif ^^DIRECTORY^^
        AddIcon /icons/blank.gif ^^BLANKICON^^
    </IfModule>

    # Security headers
    <IfModule mod_headers.c>
        Header set X-Content-Type-Options "nosniff"
        Header set X-Frame-Options "SAMEORIGIN"
        Header set X-XSS-Protection "1; mode=block"
        Header set Referrer-Policy "strict-origin-when-cross-origin"
    </IfModule>
</Directory>

# Virtual Host example (if needed)
# <VirtualHost *:80>
#     ServerName handbook.bbsengine.org
#     ServerAlias docs.bbsengine.org
#     DocumentRoot /home/opencode/data/work/bbsengine6/handbook/
#
#     <Directory "/home/opencode/data/work/bbsengine6/handbook/">
#         Options +Indexes +FollowSymLinks
#         AllowOverride All
#         Require all granted
#     </Directory>
#
#     ErrorLog ${APACHE_LOG_DIR}/handbook-error.log
#     CustomLog ${APACHE_LOG_DIR}/handbook-access.log combined
# </VirtualHost>
