.htaccess (htaccess.txt)

#  Please save this file as UTF-8 without BOM after editing it!
#
#  ---
#
#  This file is part of the Aneamal Translator.
#
#  Copyright 2010-2022 Martin Janecke <aneamal@prlbr.de>
#
#  Permission to use, copy, modify, and distribute this software for any
#  purpose with or without fee is hereby granted, provided that the above
#  copyright notice and this permission notice appear in all copies.
#
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#  ---
#
#  .htaccess
#
#  This file passes HTTP requests of Aneamal files to "aneamal/main.php" or
#  redirects them -- depending on whether the request uses the preferred URI or
#  not. Besides, this file 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: 29