Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Last active July 14, 2025 18:38
Show Gist options
  • Save arkenidar/62cc69eadfbe6372f8b0994ce2b10163 to your computer and use it in GitHub Desktop.
Save arkenidar/62cc69eadfbe6372f8b0994ce2b10163 to your computer and use it in GitHub Desktop.
/var/www/arkenidar.com/.htaccess
# .htaccess file for arkenidar.com
# This file is used to configure Apache web server settings for the arkenidar.com domain.
# It includes rules for URL rewriting, directory listings, and file handling.
# It is placed in the root directory of the website to apply these settings globally.
# Note: This file is not used for the arkenidar.com/var directory, which has its own .htaccess file.
###########################################################
# main handling of the site
###########################################################
RewriteEngine on
# a directory
RewriteCond %{REQUEST_FILENAME} -d
# without index files
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
# exception case: explicitly use Apache dirlist
RewriteCond %{REQUEST_FILENAME} !(.*\/_.*)
RewriteRule (.*) php/dirlist/dirlist.php
########################
# .html and .htm files made properly downloadable
# (see mobile edge mis-using blink for handling downloads)
<FilesMatch "\.html?$" >
ForceType text/html
### a2enmod headers && systemctl restart apache2
# Prevent caching to ensure headers are always fresh
Header always set Cache-Control "no-cache, no-store, must-revalidate"
Header always set Pragma "no-cache"
Header always set Expires "0"
# Alternative approach using RewriteEngine
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)download($|&|=) [NC]
RewriteRule .* - [E=FORCE_DOWNLOAD:1]
# Set environment variable if download parameter is present (with optional value)
SetEnvIf Query_String "download" has_download
# Only set download header if 'download' parameter is present
Header always set Content-Disposition "attachment" env=has_download
Header always set Content-Disposition "attachment" env=FORCE_DOWNLOAD
# Debug header to confirm parameter detection
Header always set X-Download-Detected "yes" env=has_download
Header always set X-Download-Detected-Alt "yes" env=FORCE_DOWNLOAD
</FilesMatch>
###########################################################
# .love files made properly downloadable
# https://love2d.org/wiki/Downloadable_files
<FilesMatch "\.love$" >
ForceType application/octet-stream
### a2enmod headers && systemctl restart apache2
Header set Content-Disposition attachment
</FilesMatch>
###########################################################
# C.O.R.S. setup
# https://stackoverflow.com/questions/32273606/how-to-enable-cors-for-apache-httpd-server-step-by-step-process
# edit your conf/httpd.conf file. Verify that the headers module is loaded
#LoadModule headers_module modules/mod_headers.so
# to whitelist every origin, use
############Header set Access-Control-Allow-Origin "*"
AddDefaultCharset UTF-8
<FilesMatch "\.txt$" >
Header set Content-type "text/plain; charset=utf-8"
</FilesMatch>
<FilesMatch "\.md$" >
Header set Content-type "text/plain; charset=utf-8"
</FilesMatch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment