# Do not allow listing of directory content:
IndexIgnore *
Options -Indexes +FollowSymLinks

#-------------------------------------------------------------------------------
# Paths to include from in include() and requre() function.
# For PHP-FPM these are set in .user.ini, for PHP_MOD they are set here.
#-------------------------------------------------------------------------------
<IfModule mod_php7.c>
	php_value include_path '.:/var/www/html/k2exo:/var/www/html/aadc-shared'
</IfModule>
<IfModule mod_php.c>
	php_value include_path '.:/var/www/html/k2exo:/var/www/html/aadc-shared'
</IfModule>
<Files ".user.ini">
    Require all denied
</Files>

#-------------------------------------------------------------------------------
# Protection against ClickJacking
#-------------------------------------------------------------------------------
<IfModule mod_headers.c>
	Header always set X-FRAME-OPTIONS "SAMEORIGIN"
</IfModule>

#-------------------------------------------------------------------------------
# URL Rewrites
#-------------------------------------------------------------------------------
# Rewrite old addresses to new:
RewriteEngine On
RewriteBase /

# Publications:
#RewriteRule ^publications/?$ /pub.php [L,NC]
#RewriteRule ^publications/(\d+)/?$ /publications.php?id=$1 [L,NC]
#RewriteRule ^publications/(\d+)/fulltext/?$ /download_publication.php?id=$1 [L,NC]
#RewriteRule ^publications/(\w+)/?$ /publications.php?list=$1 [L,NC]
#RewriteRule ^publications/feed/(\w+)/(\d+)-(\w+)/?$ /pub_feed.php?fid=$1&uid=$2&key=$3 [L,NC]

# Star Catalog:
RewriteRule ^catalog/(\d+)/?$ /catalog/index.php?starid=$1 [L,NC]

# Proposals:
RewriteRule ^proposals/?$ /info_proposals.php [L,NC]
RewriteRule ^proposals/(\d+)/?$ /proposal.php?id=$1 [L,NC]

# Fix from images to Images directory:
RewriteRule ^Images(/.*)?$ /images$1 [L]

# Catch for hidden emails:
RewriteRule ^contact/(.+)/(.+)$ /contact.php?n=$1&d=$2 [L,NC]

# Deny access to all files ending with ~:
<FilesMatch "~$">
	Deny from all
</FilesMatch>

# Deny access to version control directories
# Should already be done in httpd.conf, but this is to make sure:
RewriteRule ^(.*/)?\.(svn|git|hg|bzr|cvs)/ - [F,L]

# Error pages:
#ErrorDocument 500 /errors/500InternalServerError.php
#ErrorDocument 404 /errors/404NotFound.php
#ErrorDocument 403 /errors/403Forbidden.php
#ErrorDocument 401 /errors/401Unauthorized.php

#-------------------------------------------------------------------------------
# WebP image format
#-------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
	# TODO: don't forget to put
	# AddType image/webp .webp
	# in your mods-available/mime.conf
	# (though this is optional because we're setting
	# the mime type manually in the RewriteRule)

	# Enable rewrite
	RewriteEngine On

	# Does browser support WebP?
	RewriteCond %{HTTP_ACCEPT} \bimage/webp\b

	# Capture image name
	RewriteCond %{REQUEST_URI} (.*)\.(jpe?g|png)$

	# if you don't have all jpg/png images available
	# as webp then you want to uncomment the next line
	# so apache first checks if there is a webp file
	# otherwise leave it disabled as it removes the
	# need to query the disk
	RewriteCond %{DOCUMENT_ROOT}%1.webp -f

	# Route to WebP image
	RewriteRule .* %1\.webp [L,T=image/webp]

	<IfModule mod_headers.c>
		<FilesMatch "\.(jpe?g|png)$">
			Header append Vary Accept
		</FilesMatch>
	</IfModule>
</IfModule>

#-------------------------------------------------------------------------------
# Compression
#-------------------------------------------------------------------------------
<IfModule mod_deflate.c>
	# Compress all text, html, javascript, css and favicon:
	AddOutputFilterByType DEFLATE application/xhtml+xml
	AddOutputFilterByType DEFLATE application/xml
	AddOutputFilterByType DEFLATE application/atom+xml
	AddOutputFilterByType DEFLATE text/css
	AddOutputFilterByType DEFLATE text/html
	AddOutputFilterByType DEFLATE text/plain
	AddOutputFilterByType DEFLATE text/xml
	AddOutputFilterByType DEFLATE image/x-icon
	
	# Deal with JavaScript MIME type issues
	AddOutputFilterByType DEFLATE application/javascript
	AddOutputFilterByType DEFLATE application/x-javascript
	AddOutputFilterByType DEFLATE text/ecmascript
	AddOutputFilterByType DEFLATE text/javascript
	
	# Removes some bugs
	BrowserMatch ^Mozilla/4 gzip-only-text/html
	BrowserMatch ^Mozilla/4\.0[678] no-gzip
	BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
	Header append Vary User-Agent
	
	# Turn it off for the download scripts
	# It messes up the headers that is set by these scripts
	SetEnvIfNoCase Request_URI download\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_bundle\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_special\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_proposal\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_publication\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_conference\.php$ no-gzip dont-vary
	SetEnvIfNoCase Request_URI download_cbv\.php$ no-gzip dont-vary
</IfModule>

#-------------------------------------------------------------------------------
# Expires header
#-------------------------------------------------------------------------------
AddType image/x-icon ico
<IfModule mod_expires.c>
	ExpiresActive on
	# Graphics, Flash, Video, Icons and PDF:
	ExpiresByType application/pdf "access plus 24 hours"
	ExpiresByType application/x-shockwave-flash "access plus 7 days"
	ExpiresByType image/bmp "access plus 7 days"
	ExpiresByType image/gif "access plus 7 days"
	ExpiresByType image/jpeg "access plus 7 days"
	ExpiresByType image/jpg "access plus 7 days"
	ExpiresByType image/png "access plus 7 days"
	ExpiresByType image/webp "access plus 7 days"
	ExpiresByType image/svg+xml "access plus 7 days"
	ExpiresByType image/tiff "access plus 7 days"
	ExpiresByType image/x-icon "access plus 7 days"
	ExpiresByType text/css "access plus 24 hours"
	ExpiresByType video/x-flv "access plus 7 days"
	# JavaScript:
	ExpiresByType application/javascript "access plus 2 days"
	ExpiresByType application/x-javascript "access plus 2 days"
	ExpiresByType text/ecmascript "access plus 2 days"
	ExpiresByType text/javascript "access plus 2 days"
</IfModule>

#-------------------------------------------------------------------------------
# Caching
#-------------------------------------------------------------------------------
<IfModule mod_headers.c>
	<FilesMatch "\.(bmp|flv|gif|ico|jpg|jpeg|pdf|png|svg|swf|tif|tiff|webp)$">
		Header add Cache-Control "public"
		Header unset ETag
		Header unset Last-Modified
		FileETag none
	</FilesMatch>
</IfModule>
