##
# phpMyFAQ .htaccess file for Apache 2.x
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
#
# @author    Thorsten Rinne <thorsten@phpmyfaq.de>
# @author    Patrick Preuster <sica@php-q.net>
# @author    Matteo Scaramuccia <matteo@scaramuccia.com>
# @copyright 2004-2024 phpMyFAQ Team
# @license   http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
# @link      https://www.phpmyfaq.de
# @since     2004-11-13
DirectoryIndex index.php
# always follow the symlinks
<IfModule mod_negotiation.c>
    Options +FollowSymlinks -MultiViews -Indexes
</IfModule>
# X-Frame-Options to prevent clickjacking
Header always append X-Frame-Options SAMEORIGIN
# CORS
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
# Set cache control
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control "max-age=84600, no-store"
    Header set Pragma "no-cache"
</filesMatch>
# Set Gzip compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
</IfModule>
# Enable Expires headers to set expiration dates for various file types
<IfModule mod_expires.c>
    ExpiresActive On
    # Set expiration for image files to 1 year
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "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/x-icon "access plus 1 year"
    # Set expiration for video files to 1 year
    ExpiresByType video/webm "access plus 1 year"
    ExpiresByType video/mp4 "access plus 1 year"
    ExpiresByType video/mpeg "access plus 1 year"
    # Set expiration for font files to 1 year
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
    # Set expiration for CSS and JavaScript files to 1 year
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    # Set expiration for other file types to 1 year
    ExpiresByType application/pdf "access plus 1 year"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
</IfModule>
# Enable Cache-Control headers to set caching policies for various file types
<IfModule mod_headers.c>
    <FilesMatch "\.(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp|webm|js|pdf|css|woff|woff2)$">
        Header set Cache-Control "max-age=31536000, public"
    </FilesMatch>
</IfModule>
# Set mod_rewrite
<IfModule mod_rewrite.c>
    # This has to be 'On'
    RewriteEngine On
    <IfModule mod_fcgid.c>
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    </IfModule>
    # the path to your phpMyFAQ installation
    RewriteBase /
    # Error pages
    ErrorDocument 404 /index.php?action=404
    # General pages
    RewriteRule add-faq.html$ index.php?action=add [L,QSA]
    RewriteRule add-question.html$ index.php?action=ask [L,QSA]
    RewriteRule show-categories.html$ index.php?action=show [L,QSA]
    RewriteRule ^(search|open-questions|contact|glossary|overview|login|privacy)\.html$ index.php?action=$1 [L,QSA]
    RewriteRule ^(login) index.php?action=login [L,QSA]
    # start page
    RewriteRule ^index.html$ index.php [PT]
    # a solution ID page
    RewriteCond %{REQUEST_URI} solution_id_([0-9]+)\.html$ [NC]
    RewriteRule ^solution_id_(.*)\.html$ index.php?solution_id=$1 [L,QSA]
    # the bookmarks page
    RewriteRule ^bookmarks\.html$ index.php?action=bookmarks [L,QSA]
    # phpMyFAQ faq record page
    RewriteRule ^content/([0-9]+)/([0-9]+)/([a-z\-_]+)/(.+)\.htm(l?)$ index.php?action=faq&cat=$1&id=$2&artlang=$3 [L,QSA]
    # phpMyFAQ category page with page count
    RewriteRule ^category/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=show&cat=$1&seite=$2 [L,QSA]
    # phpMyFAQ category page
    RewriteRule ^category/([0-9]+)/(.+)\.htm(l?)$ index.php?action=show&cat=$1 [L,QSA]
    # phpMyFAQ news page
    RewriteRule ^news/([0-9]+)/([a-z\-_]+)/(.+)\.htm(l?)$ index.php?action=news&newsid=$1&newslang=$2 [L,QSA]
    # phpMyFAQ sitemap
    RewriteRule ^sitemap/([^\/]+)/([a-z\-_]+)\.htm(l?)$ index.php?action=sitemap&letter=$1&lang=$2 [L,QSA]
    # phpMyFAQ Google sitemap
    RewriteRule ^sitemap.xml$ sitemap.xml.php [L]
    RewriteRule ^sitemap.gz$ sitemap.xml.php?gz=1 [L]
    RewriteRule ^sitemap.xml.gz$ sitemap.xml.php?gz=1 [L]
    # phpMyFAQ tags page with page count
    RewriteRule ^tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=search&tagging_id=$1&seite=$2 [L,QSA]
    # phpMyFAQ tags page
    RewriteRule ^tags/([0-9]+)/([^\/]+)\.htm(l?)$ index.php?action=search&tagging_id=$1 [L,QSA]
    # Authentication services
    RewriteRule ^services/webauthn(.*) services/webauthn/index.php [L,QSA]
    # User pages
    RewriteRule ^user/(ucp|bookmarks|request-removal|logout|register) index.php?action=$1 [L,QSA]
    # Setup and update pages
    RewriteRule ^setup/(.*) setup/index.php [L,QSA]
    RewriteRule ^update/(.*) update/index.php [L,QSA]
    # Administration API
    RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
    # Private APIs
    RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
    # Setup APIs
    RewriteRule ^api/setup/(check|backup|update-database) api/index.php [L,QSA]
    # REST API v3.0
    # * http://[...]/api/v3.0/<ACTION>
    RewriteRule ^api/v3.0/(.*) api/index.php [L,QSA]
</IfModule>
