# 
# This file is an Apache config file for running Zenario in Apache version 2.2.
# 
# To use this file, remove the following line from your httpd.conf:
# 	AccessFileName .htaccess
# 
# ...and then replace it with:
# 	AccessFileName apache-2.2.htaccess .htaccess
# 


Options -Indexes -MultiViews

# Uncomment this line and replace /SUBDIRCTORY/ with your subdirectory if
# you want to show the CMS' not found page in place of Apache's not found page.
#ErrorDocument 404 /SUBDIRCTORY/index.php?cID=~

<ifModule mod_headers.c>
	Header set Content-Security-Policy "default-src *; font-src * data:; img-src * data:; script-src * 'unsafe-eval' 'unsafe-inline'; style-src * 'unsafe-inline'"
	Header set Permissions-Policy "sync-xhr=(self), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=()"
	Header set Referrer-Policy strict-origin-when-cross-origin
	Header set X-Content-Type-Options nosniff
	Header set X-Frame-Options SAMEORIGIN
	Header set X-XSS-Protection "1; mode=block"
</ifModule>

<IfModule pagespeed_module>
	ModPagespeed off
</IfModule>

<IfModule mod_expires.c>
	AddType application/font-woff .woff
	AddType application/font-woff .woff2
	AddType text/css .css
	AddType text/javascript .js
	AddType image/webp .webp
	
	ExpiresActive On
	ExpiresByType application/font-woff "access plus 1 year"
	ExpiresByType text/css "access plus 1 month"
	ExpiresByType text/javascript "access plus 1 month"
	ExpiresByType image/gif "access plus 1 year"
	ExpiresByType image/jpeg "access plus 1 year"
	ExpiresByType image/png "access plus 1 year"
	ExpiresByType image/webp "access plus 1 year"
	ExpiresByType image/svg+xml "access plus 1 year"
	ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
	ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

<IfModule mod_deflate.c>
	#SetOutputFilter DEFLATE
	AddOutputFilterByType DEFLATE text/css text/csv text/html text/plain text/xml text/javascript application/javascript application/x-javascript
	<IfModule mod_php7.c>
		php_flag zlib.output_compression Off
	</IfModule>
</IfModule>
<IfModule !mod_deflate.c>
	<IfModule mod_php7.c>
		php_flag zlib.output_compression On
	</IfModule>
</IfModule>

<IfModule mod_rewrite.c>
	RewriteEngine On
	
	# Correct any bad relative-URLs
	RewriteRule ^[\/,A-Za-z0-9~_-]*\/(public|private|zenario|zenario_custom|zenario_extra_modules)/(.*)$ zenario/redirect.php?redirectdir=$1&redirect=$2 [L,QSA]
	
	# Redirect anyone trying to access the admin login using "admin/" to just "admin", without the slash.
	# This should not be done silently, we want the visitor to see their URL changing in their browser,
	# so we need to use a PHP script for this.
	RewriteRule ^admin/$ zenario/redirect.php?redirect=admin [L,QSA]
	
	# Favicons
	RewriteRule ^favicon.ico$ zenario/file.php?usage=favicon [L]
	
	# Admin URL:
	RewriteRule ^admin(|\.\w+)$ zenario/admin/welcome.php [L,QSA]
	RewriteRule ^organizer.php$ zenario/admin/organizer.php [L,QSA]
	
	# Staging mode URLs:
	RewriteRule ^staging.php$ zenario/staging.php [L,QSA]
	
	# Friendly URLs:
	RewriteCond %{REQUEST_URI} !/(admin|public|private|zenario|zenario_custom|zenario_extra_modules|purchased_downloads)/
	RewriteRule ^([\/,A-Za-z0-9~_-]+)(|\.htm|\.html)$ index.php?cID=$1 [L,QSA]
	
	# Download Now links:
	RewriteRule ^([\/,A-Za-z0-9~_-]+)\.download$ index.php?cID=$1&download=1 [L]
	
	# RSS feeds:
	RewriteRule ^([\/,A-Za-z0-9~_-]+)\.rss$ index.php?cID=$1&method_call=showRSS [L]
	
	# A friendly URL for the XML sitemap:
	RewriteRule ^sitemap.xml$ index.php?method_call=showSitemap [L]
	
	# A friendly URL for the robots.txt file:
	RewriteRule ^robots.txt$ index.php?method_call=robots [L]
	
	
	# Remove cached pages and stats from public view:
	RewriteRule ^cache/.*$ - [F,NC]

	# Remove the build, backup and docstore directories from public view if they were placed here:
	RewriteRule ^build/.*$ - [F,NC]
	RewriteRule ^backup/.*$ - [F,NC]
	RewriteRule ^docstore/.*$ - [F,NC]
	
	# Remove yaml files, phrases and custom frameworks from public view:
	RewriteRule ^zenario.*\.yaml$ - [F,NC]
	RewriteRule ^zenario.*/phrases/.*$ - [F,NC]
	RewriteRule ^zenario.*/admin_phrase_codes/.*$ - [F,NC]
	RewriteRule ^zenario_custom/frameworks/.*\.html$ - [F,NC]
	
	# Remove any svn directories from public view:
	RewriteRule .*\.svn.*$ - [F,NC]
	
	# A rule for testing whether the htaccess file is working
	RewriteRule ^zenario/includes/test_files/is_htaccess_working\.txt$ zenario/includes/test_files/htaccess_is_working.txt [L]
	
	# A rule to catch anything pointing to the old "libraries" directory from version 7.
	RewriteRule ^zenario/libraries/(.*)$ zenario/libs/manually_maintained/$1 [L]
</IfModule>
