---
permalink: "/.htaccess"
layout: null
eleventyExcludeFromCollections: true
excludeFromSitemap: true
---
RewriteEngine On
Options -Indexes
DirectoryIndex index.php index.html
# serve directory index files directly (index.html)
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [L]
# serve directory index files directly (index.php)
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^(.*)$ $1/index.php [L]
ErrorDocument 403 /403/index.html
ErrorDocument 404 /404/index.html
ErrorDocument 429 /429/index.html
ErrorDocument 500 /500/index.html
# dynamic page routing
## artists
RewriteRule ^music/artists/([^/]+)/?$ music/artists/dynamic.php [L]
## books
RewriteRule ^books/([^/]+)/?$ books/dynamic.php [L]
## movies
RewriteRule ^watching/movies/([^/]+)/?$ watching/movies/dynamic.php [L]
## shows
RewriteRule ^watching/shows/([^/]+)/?$ watching/shows/dynamic.php [L]
## genres
RewriteRule ^music/genres/([^/]+)/?$ music/genres/dynamic.php [L]
## tags
RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/dynamic.php [L]
## open graph assets
# w/out version
RewriteRule ^og/([a-z0-9\-]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$2&class=$1&extension=$3 [L]
# w/version
RewriteRule ^og/([a-z0-9\-]+)/([\d\.]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$3&class=$1&v=$2&extension=$4 [L]
## oembed
RewriteRule ^oembed/?$ /api/oembed.php [L]
RewriteRule ^oembed/(.+)$ /api/oembed.php?url=https://www.coryd.dev/$1 [L,QSA]
## analytics
RewriteRule ^assets/scripts/utils\.js$ /api/umami.php [QSA,L]
RewriteRule ^assets/scripts/api/send$ /api/umami.php [L]
{% for redirect in redirects -%}
Redirect {{ redirect.status_code | default: "301" }} {{ redirect.source_url }} {{ redirect.destination_url }}
{% endfor -%}
{% for pathData in headers %}
{%- for header in pathData.headers %}
Header set {{ header.header_name }} "{% if header.header_name == "Content-Disposition" and header.header_value contains 'filename="' %}{{ header.header_value | replace: '"', '' }}{% else %}{{ header.header_value }}{% endif %}"
{%- endfor %}
{% endfor %}
{%- assign userAgents = "" -%}
{% for robot in robots -%}
{%- for userAgent in robot.user_agents -%}
{%- if userAgent != "*" and userAgent != "NaN" -%}
{%- assign userAgents = userAgents | append: userAgent %}
{%- unless forloop.last -%}
{%- assign userAgents = userAgents | append: "|" -%}
{%- endunless -%}
{%- endif -%}
{%- endfor -%}
{%- endfor %}
{% if userAgents != "" or referers != "" -%}
RewriteCond %{HTTP_USER_AGENT} "{{ userAgents }}" [NC]
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteRule .* /403/index.html [L,R=403]
{%- endif %}
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/font-woff2
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json application/font-woff2
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/json "access plus 1 week"
ExpiresByType application/octet-stream "access plus 1 month"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/wasm "access plus 1 year"
Header set Cache-Control "public, max-age=31536000"
Header set Cache-Control "public, max-age=3600, must-revalidate"