ServerName app.sixfold.org
	RedirectPermanent	/ https://app.sixfold.org/
	ServerName app.sixfold.org
	ServerAdmin sixfold@sixfold.org
	DocumentRoot /srv/app.sixfold.org/www
	ErrorLog ${APACHE_LOG_DIR}/app.sixfold.org-error.log
	CustomLog ${APACHE_LOG_DIR}/app.sixfold.org-access.log combined
	ErrorDocument 404 /errors/404
	ErrorDocument 503 /errors/503
	
		# Disable .htaccess files
		AllowOverride	none
		# Disable unneeded options
		Options		none
		# Allow access to www/
		Require		all granted
                # Pass HTTP Authorization headers to PHP-FPM
                CGIPassAuth     on
	
	# PHP-FPM configuration
        # See https://serverfault.com/questions/450628/apache-2-4-php-fpm-proxypassmatch/510784
        # Required for FPM to receive POST data sent with Transfer-Encoding: chunked
        SetEnv proxy-sendcl 1
        # Forward all PHP requests to the php-fpm pool for this domain.
        
                SetHandler      "proxy:unix:/run/php/app.dev.sixfold.org.sock|fcgi://app.dev.sixfold.org"
                Header          set Cache-Control "no-store"
        
        # Set some proxy properties.
        
                ProxySet        connectiontimeout=5 timeout=240
        
	RewriteEngine On
	
		RewriteCond %{ENV:REDIRECT_STATUS} =""
		RewriteRule .* - [R=404,L]
	
	# Received: /filename.php and /filename.php exists in filesystem; Result: 301 redirect to /filename and restart request
	RewriteCond %{REQUEST_FILENAME} \.php$
	RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} -f
	RewriteRule ^/(.+)\.php$	/$1 [R=301,L]
	# Received: /filename and /filename.php exists in filesystem; Result: change /filename to /filename.php and continue processing
	RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
	RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-d
	RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.php -f
	RewriteRule ^(.+)$							$1.php [QSA]
	# Received: /filename and /filename.xml exists in filesystem; Result: rewrite to /filename.xml
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xml -f
	RewriteRule (.*) $1.xml
	# Received: /filename and /filename.xhtml exists in filesystem; Result: rewrite to /filename.xhtml
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xhtml -f
	RewriteRule (.*) $1.xhtml
	# Redirect index pages
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.php -f
	RewriteRule (.*)	$1/index.php
        # Remove trailing slashes
        RewriteRule                             ^/(.+?)/$                                       /$1 [R=301,L]
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
	RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.xml -f
	RewriteRule (.*)	$1/index.xml
	RewriteCond %{QUERY_STRING} hash=([a-z0-9]+) [NC]
	RewriteRule ^/docs /docs/%1? [L,R=301]
	# Sixfold rewrites
	RewriteRule ^/games/([0-9]+)$ /games/game.php?game=$1
	RewriteRule ^/games/([0-9]+)/feedback$ /games/feedback.php?game=$1
	RewriteRule ^/games/([0-9]+)/results$ /games/results.php?game=$1
	RewriteRule ^/games/([0-9]+)/submit$ /games/submit.php?game=$1
	RewriteRule ^/games/([0-9]+)/update$ /games/update.php?game=$1
	RewriteRule ^/doc/([a-z0-9]+)$ /docs/$1 [L,R=301] # Old site URL
	RewriteRule ^/docs/([a-z0-9]+)$ /docs/submission.php?hash=$1 [L,QSA]
	RewriteRule ^/members/([^\.]+?)$ /members/member.php?handle=$1 [L]
	# PayPal order processing rewrites
	RewriteRule /api/orders$ /games/process-order.php
	RewriteRule /api/orders/(.*)/capture$ /games/process-order.php
	SSLCertificateFile /etc/letsencrypt/live/app.sixfold.org/fullchain.pem
	SSLCertificateKeyFile /etc/letsencrypt/live/app.sixfold.org/privkey.pem
	Include /etc/letsencrypt/options-ssl-apache.conf