155 lines
5 KiB
Text
155 lines
5 KiB
Text
---
|
|
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/index.php [L]
|
|
|
|
## reading
|
|
|
|
### redirects from books
|
|
RedirectMatch 301 ^/books/years/(\d{4})/?$ /reading/years/$1
|
|
RedirectMatch 301 ^/books/years/?$ /reading/years
|
|
RedirectMatch 301 ^/books/((97[89][-]?\d{1,5}[-]?\d{1,7}[-]?\d{1,7}[-]?[\dXx]))/?$ /reading/books/$1
|
|
RedirectMatch 301 ^/books/?$ /reading
|
|
|
|
### routing
|
|
RewriteRule ^reading/?$ reading/index.html [L]
|
|
RewriteRule ^reading/years/(\d{4})/?$ reading/years/$1.html [L]
|
|
RewriteRule ^reading/books/([\dXx-]+)/?$ reading/books/index.php [L]
|
|
|
|
## movies
|
|
RewriteRule ^watching/movies/([^/]+)/?$ watching/movies/index.php [L]
|
|
|
|
## shows
|
|
RewriteRule ^watching/shows/([^/]+)/?$ watching/shows/index.php [L]
|
|
|
|
## genres
|
|
RewriteRule ^music/genres/([^/]+)/?$ music/genres/index.php [L]
|
|
|
|
## tags
|
|
RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/index.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 %}
|
|
<FilesMatch "{{ pathData.resource_path }}">
|
|
{%- 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 %}
|
|
</FilesMatch>
|
|
{% endfor %}
|
|
|
|
{%- assign escapedAgents = "" -%}
|
|
{%- for robot in robots -%}
|
|
{%- for agent in robot.user_agents -%}
|
|
{%- if agent != "*" and agent != "NaN" -%}
|
|
{%- assign escaped = agent | regexEscape -%}
|
|
{%- assign escapedAgents = escapedAgents | append: escaped | append: "|" -%}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- endfor -%}
|
|
{%- assign userAgentsRegex = escapedAgents | slice: 0, escapedAgents.size | rstrip: "|" -%}
|
|
{% if userAgentsRegex != "" %}
|
|
RewriteEngine On
|
|
RewriteCond %{HTTP_USER_AGENT} "{{ userAgentsRegex }}" [NC]
|
|
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
|
|
RewriteRule .* /api/bots.php [L]
|
|
{% endif %}
|
|
<IfModule mod_deflate.c>
|
|
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
|
|
</IfModule>
|
|
|
|
<IfModule mod_brotli.c>
|
|
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json
|
|
</IfModule>
|
|
|
|
<IfModule mod_expires.c>
|
|
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 year"
|
|
ExpiresByType application/javascript "access plus 1 year"
|
|
ExpiresByType image/jpeg "access plus 1 year"
|
|
ExpiresByType image/png "access plus 1 year"
|
|
ExpiresByType image/gif "access plus 1 year"
|
|
ExpiresByType image/svg+xml "access plus 1 year"
|
|
ExpiresByType image/x-icon "access plus 1 year"
|
|
ExpiresByType application/json "access plus 1 week"
|
|
ExpiresByType application/octet-stream "access plus 1 year"
|
|
ExpiresByType font/ttf "access plus 1 year"
|
|
ExpiresByType font/otf "access plus 1 year"
|
|
ExpiresByType application/wasm "access plus 1 year"
|
|
</IfModule>
|
|
|
|
<IfModule mod_headers.c>
|
|
Header append Vary "Accept-Encoding"
|
|
|
|
<FilesMatch "\.(js|css|woff2|ttf|otf|png|jpg|jpeg|gif|svg|wasm|ico)$">
|
|
Header set Cache-Control "public, max-age=31536000, immutable"
|
|
</FilesMatch>
|
|
</IfModule>
|
|
|
|
<IfModule mod_mime.c>
|
|
AddType font/woff2 .woff2
|
|
AddType font/ttf .ttf
|
|
AddType font/otf .otf
|
|
</IfModule>
|
|
|
|
<IfModule mod_rewrite.c>
|
|
RewriteEngine On
|
|
|
|
# use brotli if available
|
|
RewriteCond %{HTTP:Accept-Encoding} br
|
|
RewriteCond %{REQUEST_FILENAME}.br -f
|
|
RewriteRule ^(.*)$ $1.br [QSA,L]
|
|
|
|
# fallback to gzip
|
|
RewriteCond %{HTTP:Accept-Encoding} gzip
|
|
RewriteCond %{REQUEST_FILENAME}.gz -f
|
|
RewriteRule ^(.*)$ $1.gz [QSA,L]
|
|
</IfModule>
|