.htaccess (htaccess.txt)

#  Copyright 2010-2024 Martin Janecke <martin@aneamal.org>
#
#  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/.
#
#  ---
#
#  .htaccess
#
#  This file passes the HTTP request of an Aneamal file to "aneamal/main.php" or
#  redirects it, if the request does not use the preferred URI yet. This file
#  also configures web server settings and whether the Aneamal Translator caches
#  pages.


#  Aneamal cache configuration
#
#  To make the Aneamal Translator cache generated HTML output, change the
#  permissions of the directory "aneamal/private" to be writable and remove the
#  #-character before the following "SetEnv AneamalCache on" statement. Write
#  "SetEnv AneamalCache forced" to enable the cache for POST queries, too. Write
#  "SetEnv AneamalCache 3601" to enable the cache for 3601 seconds.
#
#  SetEnv AneamalCache on


#  Aneamal home address
#
#  The Aneamal translator uses the SCRIPT_NAME variable to determine the home
#  address of the Aneamal installation for creating authority-relative URLs in
#  the output. Sometimes the SCRIPT_NAME variable is not reliable though. In
#  that case remove the #-character before the "SetEnv AneamalHome /" statement.
#  You can replace the slash with your desired path. The path should start with
#  a slash. It should end without a slash unless it is just the slash.
#
#  SetEnv AneamalHome /


#  Deactivate MultiViews content negotiation
#
#  This prevents the server from automatically choosing a file which resembles
#  the request. Example: There are two files "foo.txt" and "foo.nml"; the user
#  requests "foo"; with MultiViews activated the server might decide to serve
#  the file "foo.txt" although "foo.nml" should be used, as defined later.

Options -MultiViews


#  Deactivate adding slashes to directory names automatically
#
#  Example: There is a file "foo.nml" and a directory "foo/"; the user requests
#  "foo"; with DirectorySlash enabled the server would redirect to "foo/"
#  although "foo.nml" should be used, as defined later. Later we also define
#  that "foo" redirects to "foo/" if "foo/" exists and "foo.nml" does not.

DirectorySlash Off


#  Set directory index files
#
#  The DirectoryIndex directive sets files that are automatically served if a
#  directory is requested in which they are present and "index.nml" is not. Do
#  NOT add "index.nml" here; it is set as primary directory index file later.

DirectoryIndex index.html index.php index.txt


#  Activate the mod_rewrite engine
#
#  This prepares for the coming RewriteCond and RewriteRule statements. The
#  string "foo" serves as a placeholder for any reasonable string in the
#  comments accompanying these statements.

RewriteEngine on


#  Block access to "aneamal/main.php" and the "aneamal/private" directory
#
#  These URLs should not be called directly, as this could cause identical
#  content to be accessible at multiple addresses.

RewriteRule ^aneamal/(cache|main|private) - [F,END]


#  Redirect "foo/index" to "foo/"
#
#  "index.nml" is the default directory index file: it is shown whenever the
#  directory is requested. In order to prevent the file from being accessible
#  at multiple URLs, calling the file directly redirects to the directory.

RewriteCond %{REQUEST_FILENAME}.nml -f
RewriteRule ^(.*/)?index$ /$1 [R=301,END]


#  Redirect requests that include the ".nml" file extension
#
#  Aneamal files are used without file extension in URLs. The advantages include
#  less typing and being able to switch from Aneamal to another system without
#  having to change the URLs.

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*/)?index\.nml$ /$1 [R=301,END]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.nml$ /$1 [R=301,END]


#  Pass Aneamal files to the Aneamal Translator
#
#  This handles requests for directories containing an Aneamal directory index
#  file and requests for other existing Aneamal files. The Aneamal Translator is
#  called to process the requested file.

RewriteCond %{REQUEST_FILENAME}index.nml -f
RewriteRule ^(.*/)?$ aneamal/main.php?/$1index.nml [END]
RewriteCond %{REQUEST_FILENAME}.nml -f
RewriteRule ^(.+)$ aneamal/main.php?/$1.nml [END]


#  Mimic the DirectorySlash directive
#  
#  This redirects "foo" to "foo/", but after having checked that "foo.nml" does
#  not exist. This is like the DirectorySlash directive deactivated above
#  without the negative side effect of some Aneamal files not being accessible.

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ /$1/ [R=301,END]


# Last changed: 31