# sending 404 implies that the page was removed by accident.
RewriteEngine On
# Check if the requested URL is NOT an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Check if the requested URL is NOT an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Return a 410 Gone status for everything else
RewriteRule ^.*$ - [G,L]
ErrorDocument 410 "this URL intentionally left blank"


# file redirects
Redirect 301 /.well-known/avatar /assets/images/author.jpg
Redirect 301 /.well-known/button /assets/images/starbreaker-88x31.png
Redirect 301 /.well-known/ai-instructions.txt /agents.md
Redirect 301 /follow/everything.xml /feed.xml
Redirect 301 /follow/headlines.xml /headlines.xml
Redirect 301 /for.html /dedication.html


# Got referred here by Hacker News
# or a shitty search engine, social platform, or forum?
# Computer says, ‘fuck you.’
RewriteCond %{HTTP_REFERER} news.ycombinator.com [NC,OR]
RewriteCond %{HTTP_REFERER} facebook.com [NC,OR]
RewriteCond %{HTTP_REFERER} threads.net [NC,OR]
RewriteCond %{HTTP_REFERER} instagram.com [NC,OR]
RewriteCond %{HTTP_REFERER} bsky.app [NC,OR]
RewriteCond %{HTTP_REFERER} reddit.com [NC]
RewriteRule .* . [redirect=402,last]
ErrorDocument 402 "you came from a platform that does not pay me"


# Did you come here from a Nazi bar? Fuck off.
RewriteCond %{HTTP_REFERER} x.com [NC,OR]
RewriteCond %{HTTP_REFERER} twitter.com [NC,OR]
RewriteCond %{HTTP_REFERER} 4chan.org [NC,OR]
RewriteCond %{HTTP_REFERER} forum.agoraroad.com [NC]
RewriteRule .* . [redirect=403,last]
ErrorDocument 403 "NAZI PUNKS FUCK OFF"


# these assholes have bullied at least 2 trans folks to the point of suicide
RewriteCond %{HTTP_REFERER} kiwifarms.net [NC]
RewriteRule .* . [redirect=403,last]
ErrorDocument 403 "you are one of Joshua Moon’s lolcows"


# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
# 410 gone for a long string of lowercase letters
# and/or numbers followed by an optional long extension
# to handle spam URLs like /spstyaaliti4csf6ne.desiringly
RewriteRule ^/?[a-z0-9]{12,30}(\.[a-z0-9]{8,30})?$ - [G,L]


# This is a static site, assholes. Stop trying to look for shit to exploit.
RewriteRule \.php$ . [redirect=410,last]
RewriteRule \.aspx$ . [redirect=410,last]
RewriteRule \.asp$ . [redirect=410,last]
RewriteRule \.jsp$ . [redirect=410,last]
ErrorDocument 410 "meow"


# Deny the image scraper
# https://imho.alex-kunz.com/2024/02/25/block-this-shit/
RewriteCond "%{HTTP_USER_AGENT}" "Firefox/72.0" [nocase]
RewriteRule .* . [redirect=410,last]
ErrorDocument 410 "meow"


# No directory listings, please. We're British.
IndexIgnore *
DirectoryIndex index.html


# UNICODE OR GTFO!
AddDefaultCharset utf-8


# Set time zone for site
SetEnv TZ America/New_York


# Set the cache-control max-age
# 1 year
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf|webp|avif)$">
Header set Cache-Control "max-age=31449600, public, must-revalidate"
</FilesMatch>
# 1 month
<FilesMatch ".(js|css)$">
Header set Cache-Control "max-age=2628000, public, must-revalidate"
</FilesMatch>
# 1 hours
<FilesMatch ".(html|htm|xml|txt|md)$">
Header set Cache-Control "max-age=3600, public, must-revalidate"
</FilesMatch>


# Turn off the ETags
Header unset ETag
FileETag None

<IfModule mod_mime.c>
    AddType application/xml .xml .opml
    AddType text/plain .txt .md .markdown .org
    AddCharset UTF-8 .html .htm .txt .md .markdown .org .atom .css .js .json .rss .opml .xml .xsl
</IfModule>


# BEGIN compression
# Brotli with Gzip fallback
<IfModule mod_brotli.c>
    # Enable Brotli compression
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml image/svg+xml
</IfModule>
<IfModule !mod_brotli.c>
    # Fallback to Gzip if Brotli is not installed/enabled
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml image/svg+xml
    </IfModule>
</IfModule>

# 3. Ensure proxies deliver the correct content type based on browser support
<IfModule mod_headers.c>
    Header append Vary User-Agent
</IfModule>
# END compression


# BEGIN custom headers
<IfModule mod_headers.c>
Header set Expect-CT "max-age=86400, enforce"
Header always set Permissions-Policy "accelerometer=(); ambient-light-sensor=(); autoplay=(); battery=(); camera=(); display-capture=(); document-domain=(); encrypted-media=(); execution-while-not-rendered=(); execution-while-out-of-viewport=(); fullscreen=(); geolocation=(); gyroscope=(); layout-animations=(); legacy-image-formats=(); magnetometer=(); microphone=(); midi=(); navigation-override=(); oversized-images=(); payment=(); picture-in-picture=(); publickey-credentials-get=(); sync-xhr=(); vr=(); wake-lock=(); screen-wake-lock=(); web-share=(self); xr-spatial-tracking=();"
Header set X-Chromosomes "Women have 'em, but so does every man. Get over it, guys. You’d be a miscarriage without that chromosome you got from your mothers, and let’s not even get started on mitochondrial DNA. That comes from yo momma, too. (Do you even science, bro?)"
Header set X-Is-A-Nazi-Bar "It was one in 2016. It only got once once Apartheid Baby bought it. Being there is not a good look. Delete your account today."
Header set X-Christian "Heaven is Omelas, and Judas Iscariot is the kid in the basement. His betrayal was the true sacrifice; without it Jesus would not have been crucified."
Header set X-Robots-Tag "noai, noimageai, GPC"
Header set X-Guru-Meditation "🤘 VAN HALEN 0x141E 🤘"
Header set X-Japan "🤘 INTERTEXTUAL VIOLENCE CRIME OF LITERARY SHOCK 🤘"
Header set X-Spaceballs "If you can read this, you don't need glasses."

<FilesMatch "\.(js|css|pdf|xml|xsl|gz|eot|svg|ttf|woff|woff2|svg|webmanifest|txt)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

<IfModule mod_mime.c>
</IfModule>
# END custom headers
