HTACCESS: Difference between revisions

From NikkiWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 24: Line 24:
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
# https://www.mediawiki.org/wiki/Manual:Short_URL/Apache#Setting_up_the_rewrite_rules
# https://www.mediawiki.org/wiki/Manual:Short_URL/Apache#Setting_up_the_rewrite_rules
</syntaxhighlight>
== MEDIAWIKI files ==
# [https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset <cite>Apache HTTP Server Project Documentation</cite>: "Multipurpose Internet Mail Extension (MIME) Module"]
MediaWiki source code saved as MEDIAWIKI filetype will not display in the web browser unless you set the Multipurpose Internet Mail Extension (MIME) type for MEDIAWIKI to "<code>text/plain</code>".
<syntaxhighlight lang="apache">
AddType text/plain .mediawiki
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype
</syntaxhighlight>
== character encoding ==
Unicode special characters encoded as Eight-Bit Unicode Transformation Format (UTF-8) in plaintext (TXT) files and in MEDIAWIKI files will not display correctly in the browser unless the character set (charset) encoding is manually set for these filetypes.&ensp; You should set the charset for each filetype individually and should not use "<syntaxhighlight lang="apache" inline="inline">AddDefaultCharset</syntaxhighlight>".
<syntaxhighlight lang="apache">
AddCharset UTF-8 .mediawiki .txt
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset
</syntaxhighlight>
</syntaxhighlight>


Line 35: Line 55:
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=*
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=*
DefaultIcon /icons/000.svg
DefaultIcon /icons/000.svg
AddIcon /icons/zzz.svg ^^DIRECTORY^^
AddIcon /images/icons/filetypes/zzz.svg ^^DIRECTORY^^
AddIcon /icons/htm.svg .htm .html
AddIcon /images/icons/filetypes/7z0.svg .7z
AddIcon /icons/svg.svg .svg
AddIcon /images/icons/filetypes/css.svg .css
AddIcon /icons/txt.svg .txt
AddIcon /images/icons/filetypes/htm.svg .htm .html
AddIcon /icons/xls.svg .xls .xlsm .xlsx
AddIcon /images/icons/filetypes/med.svg .mediawiki
AddIcon /images/icons/filetypes/png.svg .png
AddIcon /images/icons/filetypes/svg.svg .svg
AddIcon /images/icons/filetypes/txt.svg .txt
IndexOptions +IconsAreLinks
IndexOptions +IconsAreLinks
ReadmeName /footer.html
ReadmeName /footer.html
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html
</syntaxhighlight>
== character encoding ==
# [https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset <cite>Apache HTTP Server Project Documentation</cite>: "Multipurpose Internet Mail Extension (MIME) Module (Add Charset)"]
Unicode plaintext (TXT) files will not display correctly in the browser unless the character set (charset) encoding for TXT files is manually set to "UTF-8" (Unicode Transformation Format, Eight-Bit).
<syntaxhighlight lang="apache">
AddCharset UTF-8 .txt # https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset
</syntaxhighlight>
</syntaxhighlight>



Revision as of 2026-04-14T05:23:51

Resources for configuring Apache Hypertext Transfer Protocol (HTTP) Server Access (.htaccess) files.

intro

  1. Wikipedia: "HTACCESS"
  2. DreamHost Knowledge Base: "HTACCESS Overview"
  3. DreamHost Knowledge Base: "What Can I Do with an HTACCESS File?"
  4. Apache HTTP Server Project Documentation: "HTACCESS Files"

redirects

  1. DreamHost Knowledge Base: "How Can I Redirect and Rewrite my Uniform Resource Locators (URLs) with an HTACCESS File?"
  2. Wikipedia: "HTTP Status Codes"
  3. Mozilla Developer Network: "HTTP Response Status Codes"
  4. Internet Engineering Task Force (IETF) HTTP Working Group: "Internet Standard 97 (HTTP Semantics: Overview of Status Codes)"

MediaWiki shortlinks

  1. Wikimedia MediaWiki: "Apache Short URL"
RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
# https://www.mediawiki.org/wiki/Manual:Short_URL/Apache#Setting_up_the_rewrite_rules

MEDIAWIKI files

  1. Apache HTTP Server Project Documentation: "Multipurpose Internet Mail Extension (MIME) Module"

MediaWiki source code saved as MEDIAWIKI filetype will not display in the web browser unless you set the Multipurpose Internet Mail Extension (MIME) type for MEDIAWIKI to "text/plain".

AddType text/plain .mediawiki
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addtype

character encoding

Unicode special characters encoded as Eight-Bit Unicode Transformation Format (UTF-8) in plaintext (TXT) files and in MEDIAWIKI files will not display correctly in the browser unless the character set (charset) encoding is manually set for these filetypes.  You should set the charset for each filetype individually and should not use "AddDefaultCharset".

AddCharset UTF-8 .mediawiki .txt
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset

automatic indexing

  1. Apache HTTP Server Project Documentation: "Automatic Index Module"

"FancyIndexing" must be enabled before adding icons.  "IconsAreLinks" can only be enabled after the icons are added.

IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=*
DefaultIcon /icons/000.svg
AddIcon /images/icons/filetypes/zzz.svg ^^DIRECTORY^^
AddIcon /images/icons/filetypes/7z0.svg .7z
AddIcon /images/icons/filetypes/css.svg .css
AddIcon /images/icons/filetypes/htm.svg .htm .html
AddIcon /images/icons/filetypes/med.svg .mediawiki
AddIcon /images/icons/filetypes/png.svg .png
AddIcon /images/icons/filetypes/svg.svg .svg
AddIcon /images/icons/filetypes/txt.svg .txt
IndexOptions +IconsAreLinks
ReadmeName /footer.html
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html

HTACCESS for Nicole Sharp's Website

RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
# https://www.mediawiki.org/wiki/Manual:Short_URL/Apache#Setting_up_the_rewrite_rules

IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=*
DefaultIcon /icons/000.svg
AddIcon /icons/zzz.svg ^^DIRECTORY^^
AddIcon /icons/7z0.svg .7z
AddIcon /icons/htm.svg .htm .html
AddIcon /icons/pdf.svg .pdf
AddIcon /icons/svg.svg .svg
AddIcon /icons/txt.svg .txt
AddIcon /icons/xls.svg .xls .xlsm .xlsx
IndexOptions +IconsAreLinks
ReadmeName /footer.html
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html

AddCharset UTF-8 .txt # https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset

# Apache Hypertext Transfer Protocol Server Access (HTACCESS) for Nicole Sharp's Website: https://www.nicolesharp.net/
# Copyright (C) 2026-04-13 Nicole Sharp
# Unless otherwise noted, content on Nicole Sharp's Website is available under the Creative Commons Attribution-ShareAlike (CC BY-SA) 4.0 International Public License: https://www.nicolesharp.net/wiki/CC_BY-SA

HTACCESS footer for Nicole Sharp's Website

You can use either "footer.txt" or "footer.html" to add content to the bottom of each automatically generated indexpage.  For Hypertext Markup Language (HTML), I try to use the HTM file extension for webpages written by humans for humans versus the HTML file extension for webpages written by machines or for machines.  The "footer.html" here is not a webpage or a valid HTML document: it is just a code snippet to be inserted before the closing </body> tag.  You should not have an HTML or BODY element in the "footer.html" file.

Since this hypertext will appear frequently on many different pages, you should not use redirecting links.  In the example below, this means using the full "/wiki/Creative_Commons_Attribution-ShareAlike_4.0_International_Public_License" and not the shorter "/wiki/CC_BY-SA".  Avoiding wikiredirects here should reduce server load.

<p>© (Copyright) 2026 <a href="/wiki/Nicole_Sharp">Nicole Sharp</a> (NicoleSharp.net).</p>

<p>Unless otherwise noted, content on this site is available under the <cite><a rel="copyright" href="/wiki/Creative_Commons_Attribution-ShareAlike_4.0_International_Public_License">Creative Commons Attribution-ShareAlike 4.0 International Public License</a> (CC BY-SA 4.0)</cite>.</p>

<p><strong><a rel="home index" href="/wiki/NikkiWiki">Return to the homepage for <cite>Nicole Sharp’s Website</cite>.</a></strong></p>

references

  1. Wikibooks: "Apache HTTP Server"
  2. Apache HTTP Server Project Documentation