HTACCESS: Difference between revisions
Nicole Sharp (talk | contribs) m Nicole Sharp moved page HTACCESS to Apache Hypertext Transfer Protocol Access over redirect |
Nicole Sharp (talk | contribs) No edit summary |
||
| (17 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Resources for configuring Apache Hypertext Transfer Protocol (HTTP) Access (<code>.htaccess</code>) files. | Resources for configuring <strong>Apache Hypertext Transfer Protocol (HTTP) Server Access (<code>.htaccess</code>)</strong> files. | ||
== intro == | |||
# [[wikipedia:HTACCESS|<cite>Wikipedia</cite>: "HTACCESS"]] | |||
# [https://help.dreamhost.com/hc/articles/216456227/ <cite>DreamHost Knowledge Base</cite>: "HTACCESS Overview"] | |||
# [https://help.dreamhost.com/hc/articles/217738987/ <cite>DreamHost Knowledge Base</cite>: "What Can I Do with an HTACCESS File?"] | |||
# [https://httpd.apache.org/docs/current/howto/htaccess.html <cite>Apache HTTP Server Project Documentation</cite>: "HTACCESS Files"] | |||
== redirects == | |||
# [https://help.dreamhost.com/hc/articles/215747748/ <cite>DreamHost Knowledge Base</cite>: "How Can I Redirect and Rewrite my Uniform Resource Locators (URLs) with an HTACCESS File?"] | |||
# [[wikipedia:HTTP status codes|<cite>Wikipedia</cite>: "HTTP Status Codes"]] | |||
# [https://developer.mozilla.org/docs/Web/HTTP/Reference/Status/ <cite>Mozilla Developer Network</cite>: "HTTP Response Status Codes"] | |||
# [https://httpwg.org/specs/rfc9110.html#overview.of.status.codes <cite>Internet Engineering Task Force (IETF) HTTP Working Group</cite>: "Internet Standard 97 (HTTP Semantics: Overview of Status Codes)"] | |||
== MediaWiki shortlinks == | |||
# [[mw:Manual:Short URL/Apache|<cite>Wikimedia MediaWiki</cite>: "Apache Short URL"]] | |||
<syntaxhighlight lang="apache"> | <syntaxhighlight lang="apache"> | ||
| Line 23: | 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> | |||
== automatic indexing == | |||
# [https://httpd.apache.org/docs/current/mod/mod_autoindex.html <cite>Apache HTTP Server Project Documentation</cite>: "Automatic Index Module"] | |||
"<code>FancyIndexing</code>" must be enabled <em>before</em> adding icons.  "<code>IconsAreLinks</code>" can only be enabled <em>after</em> the icons are added. | |||
<syntaxhighlight lang="apache"> | |||
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=* | |||
DefaultIcon /icons/000.svg | |||
AddIcon /icons/zzz.svg ^^DIRECTORY^^ | |||
AddIcon /icons/htm.svg .htm .html | |||
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 | |||
</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 | |||
# https:// | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== HTACCESS for <cite>Nicole Sharp's Website</cite> == | |||
<syntaxhighlight lang="apache"> | |||
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 | |||
</syntaxhighlight> | |||
== HTACCESS footer for Nicole Sharp's Website == | |||
You can use either "<code>footer.txt</code>" or "<code>footer.html</code>" 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 "<code>footer.html</code>" here is <em>not</em> a webpage or a valid HTML document: it is just a code snippet to be inserted before the closing <syntaxhighlight lang="html" inline="inline"></body></syntaxhighlight> tag.  You should <em>not</em> have an HTML or BODY element in the "<code>footer.html</code>" 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 "<kbd>/wiki/Creative_Commons_Attribution-ShareAlike_4.0_International_Public_License</kbd>" and not the shorter "<kbd>/wiki/CC_BY-SA</kbd>".  Avoiding wikiredirects here should reduce server load. | |||
<syntaxhighlight lang="html"> | |||
<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> | |||
</syntaxhighlight> | |||
== references == | |||
# [[wikibooks:Apache|<cite>Wikibooks</cite>: "Apache HTTP Server"]] | |||
# [https://httpd.apache.org/docs/current/ <cite>Apache HTTP Server Project Documentation</cite>] | |||
[[category:webdevelopment]] | [[category:webdevelopment]] | ||
[[category:APACHE]] | |||
[[category:HTML]] | |||
Latest revision as of 2026-04-13T05:39:11
Resources for configuring Apache Hypertext Transfer Protocol (HTTP) Server Access (.htaccess) files.
intro
- Wikipedia: "HTACCESS"
- DreamHost Knowledge Base: "HTACCESS Overview"
- DreamHost Knowledge Base: "What Can I Do with an HTACCESS File?"
- Apache HTTP Server Project Documentation: "HTACCESS Files"
redirects
- DreamHost Knowledge Base: "How Can I Redirect and Rewrite my Uniform Resource Locators (URLs) with an HTACCESS File?"
- Wikipedia: "HTTP Status Codes"
- Mozilla Developer Network: "HTTP Response Status Codes"
- Internet Engineering Task Force (IETF) HTTP Working Group: "Internet Standard 97 (HTTP Semantics: Overview of Status Codes)"
MediaWiki shortlinks
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
automatic indexing
"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 /icons/zzz.svg ^^DIRECTORY^^ AddIcon /icons/htm.svg .htm .html 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
character encoding
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).
AddCharset UTF-8 .txt # https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset
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
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>