HTACCESS: Difference between revisions
Nicole Sharp (talk | contribs) |
Nicole Sharp (talk | contribs) No edit summary |
||
| (19 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Resources for configuring Apache Hypertext Transfer Protocol (HTTP) Server Access ( | Resources for configuring <strong>Apache Hypertext Transfer Protocol (HTTP) Server Access (HTACCESS)</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"] | |||
An HTACCESS file is a plaintext file named "<code>.htaccess</code>" ideally placed into the webroot ("<code>/.htaccess</code>").  There are no characters before the period in the filename. | |||
== | == 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?"] | |||
# [https://httpd.apache.org/docs/current/mod/mod_alias.html <cite>Apache HTTP Server Project Documentation</cite>: "Alias Module"] | |||
# [[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)"] | |||
If you want to temporarily redirect traffic to another site, use an HTTP 302 (<em>not</em> HTTP 301) redirect.  HTTP 302 instructs searchbots to continue indexing the host domain and to check back later to see if the temporary redirect has ceased or changed. | |||
<syntaxhighlight lang="apache"> | <syntaxhighlight lang="apache"> | ||
Redirect 302 / https://nicolesharp.dreamhosters.com/ | |||
# https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect | |||
# https://httpwg.org/specs/rfc9110.html#status.302 | |||
</syntaxhighlight> | |||
== error pages == | |||
# [https://help.dreamhost.com/hc/articles/215840318/ <cite>DreamHost Knowledge Base</cite>: "Custom Error Pages"] | |||
# [https://httpd.apache.org/docs/current/custom-error.html <cite>Apache HTTP Server Project Documentation</cite>: "Custom Error Responses"] | |||
You cannot customize the error pages for HTTP 400 or HTTP 500 errors on DreamHost shared webhosting.  Custom error pages are best served as static Hypertext Markup Language (HTML) without redirecting to a Personal Homepage Hypertext Preprocessor (PHP) application like Wikimedia MediaWiki. | |||
<syntaxhighlight lang="apache"> | |||
ErrorDocument 403 /errors/403.htm | |||
ErrorDocument 404 /errors/404.htm | |||
# https://httpd.apache.org/docs/current/custom-error.html | |||
</syntaxhighlight> | |||
== MediaWiki shortlinks == | |||
# [[mw:Manual:Short URL/Apache|<cite>Wikimedia MediaWiki</cite>: "Apache Short URL"]] | |||
<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 | |||
</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.  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> | |||
== 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 /images/icons/filetypes/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.htm | |||
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html | |||
</syntaxhighlight> | |||
== index footers == | |||
You can use either "<code>footer.txt</code>" or "<code>footer.htm</code>" to add content to the bottom of each automatically generated indexpage.  The "<code>footer.htm</code>" here is <em>not</em> a webpage or a valid Hypertext Markup Language (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.htm</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. | |||
"<code>footer.htm</code>" must be validated for HTML 3.2 — <em>not</em> HTML 4, HTML 5, or Extensible HTML (XHTML).  This means not using a FOOTER element.  Use the [https://validator.w3.org/ Worldwide Web Consortium (W3C) Markup Validation Service] to check for any disallowed elements or attributes.  Select "Validate by Direct Input" and then select "Use Doctype HTML 3.2" under "Validate Full Document".  DreamHost shared webhosting does not support <syntaxhighlight lang="apache" inline="inline">IndexOptions +FancyIndexing +XHTML</syntaxhighlight> for Apache HTACCESS. | |||
Remember to put a blank line at the end of "<code>footer.htm</code>" to create a linebreak before <syntaxhighlight lang="html" inline="inline"></body></syntaxhighlight> when the HTML is inserted.  This is not necessary for "<code>footer.txt</code>". | |||
=== HTML footer === | |||
HTACCESS HTML footer for <cite>Nicole Sharp’s Website</cite>. | |||
<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> | |||
=== text footer === | |||
HTACCESS text footer for <cite>Nicole Sharp’s Website</cite>. | |||
<syntaxhighlight lang="text"> | |||
© (Copyright) 2026 Nicole Sharp. | |||
https://www.nicolesharp.net/ | |||
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> | |||
== sample HTACCESS == | |||
HTACCESS for <cite>Nicole Sharp’s Website</cite>. | |||
<syntaxhighlight lang="apache"> | |||
ErrorDocument 403 /errors/403.htm | |||
ErrorDocument 404 /errors/404.htm | |||
# https://httpd.apache.org/docs/current/custom-error.html | |||
RewriteEngine On | RewriteEngine On | ||
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] | RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] | ||
| Line 24: | Line 140: | ||
# 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 | ||
# Apache Hypertext Transfer Protocol Server Access (HTACCESS) for Nicole Sharp's Website. | AddType text/plain .mediawiki | ||
# 2026-04- | AddCharset UTF-8 .mediawiki .txt | ||
# https://www.nicolesharp.net/ | # https://httpd.apache.org/docs/current/mod/mod_mime.html | ||
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=* | |||
DefaultIcon /images/icons/filetypes/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/doc.svg .doc | |||
AddIcon /images/icons/filetypes/dox.svg .docx | |||
AddIcon /images/icons/filetypes/htm.svg .htm .html | |||
AddIcon /images/icons/filetypes/ico.svg .ico | |||
AddIcon /images/icons/filetypes/jpg.svg .jpg .jpeg | |||
AddIcon /images/icons/filetypes/med.svg .mediawiki | |||
AddIcon /images/icons/filetypes/mht.svg .mht .mhtml | |||
AddIcon /images/icons/filetypes/ods.svg .ods | |||
AddIcon /images/icons/filetypes/odt.svg .odt | |||
AddIcon /images/icons/filetypes/oxp.svg .oxps | |||
AddIcon /images/icons/filetypes/pdf.svg .pdf | |||
AddIcon /images/icons/filetypes/png.svg .png | |||
AddIcon /images/icons/filetypes/svg.svg .svg | |||
AddIcon /images/icons/filetypes/txt.svg .txt | |||
AddIcon /images/icons/filetypes/xht.svg .xht .xhtml | |||
AddIcon /images/icons/filetypes/xls.svg .xls | |||
AddIcon /images/icons/filetypes/xlx.svg .xlsx | |||
AddIcon /images/icons/filetypes/xml.svg .xml | |||
AddIcon /images/icons/filetypes/xps.svg .xps | |||
AddIcon /images/icons/filetypes/zip.svg .zip | |||
IndexOptions +IconsAreLinks | |||
ReadmeName /footer.htm | |||
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html | |||
# Apache Hypertext Transfer Protocol Server Access (HTACCESS) for Nicole Sharp's Website: https://www.nicolesharp.net/ | |||
# Copyright (C) 2026-04-14 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> | </syntaxhighlight> | ||
== references == | == references == | ||
# [https://httpd.apache.org/ <cite>Apache HTTP Server Project</cite>] | # [[wikibooks:Apache|<cite>Wikibooks</cite>: "Apache HTTP Server"]] | ||
# [https://httpd.apache.org/docs/current/ <cite>Apache HTTP Server Project Documentation</cite>] | |||
[[category: | [[category:HTACCESS]] | ||
[[category:APACHE]] | |||
[[category:HTML]] | |||
Latest revision as of 2026-04-14T09:00:30
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"
An HTACCESS file is a plaintext file named ".htaccess" ideally placed into the webroot ("/.htaccess"). There are no characters before the period in the filename.
redirects
- DreamHost Knowledge Base: "How Can I Redirect and Rewrite my Uniform Resource Locators (URLs) with an HTACCESS File?"
- Apache HTTP Server Project Documentation: "Alias Module"
- 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)"
If you want to temporarily redirect traffic to another site, use an HTTP 302 (not HTTP 301) redirect. HTTP 302 instructs searchbots to continue indexing the host domain and to check back later to see if the temporary redirect has ceased or changed.
Redirect 302 / https://nicolesharp.dreamhosters.com/ # https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect # https://httpwg.org/specs/rfc9110.html#status.302
error pages
- DreamHost Knowledge Base: "Custom Error Pages"
- Apache HTTP Server Project Documentation: "Custom Error Responses"
You cannot customize the error pages for HTTP 400 or HTTP 500 errors on DreamHost shared webhosting. Custom error pages are best served as static Hypertext Markup Language (HTML) without redirecting to a Personal Homepage Hypertext Preprocessor (PHP) application like Wikimedia MediaWiki.
ErrorDocument 403 /errors/403.htm ErrorDocument 404 /errors/404.htm # https://httpd.apache.org/docs/current/custom-error.html
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
MEDIAWIKI files
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
"FancyIndexing" must be enabled before adding icons. "IconsAreLinks" can only be enabled after the icons are added.
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=* DefaultIcon /images/icons/filetypes/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.htm # https://httpd.apache.org/docs/current/mod/mod_autoindex.html
You can use either "footer.txt" or "footer.htm" to add content to the bottom of each automatically generated indexpage. The "footer.htm" here is not a webpage or a valid Hypertext Markup Language (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.htm" 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.
"footer.htm" must be validated for HTML 3.2 — not HTML 4, HTML 5, or Extensible HTML (XHTML). This means not using a FOOTER element. Use the Worldwide Web Consortium (W3C) Markup Validation Service to check for any disallowed elements or attributes. Select "Validate by Direct Input" and then select "Use Doctype HTML 3.2" under "Validate Full Document". DreamHost shared webhosting does not support IndexOptions +FancyIndexing +XHTML for Apache HTACCESS.
Remember to put a blank line at the end of "footer.htm" to create a linebreak before </body> when the HTML is inserted. This is not necessary for "footer.txt".
HTACCESS HTML footer for Nicole Sharp’s Website.
<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>
HTACCESS text footer for Nicole Sharp’s Website.
© (Copyright) 2026 Nicole Sharp. https://www.nicolesharp.net/ 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
sample HTACCESS
HTACCESS for Nicole Sharp’s Website.
ErrorDocument 403 /errors/403.htm
ErrorDocument 404 /errors/404.htm
# https://httpd.apache.org/docs/current/custom-error.html
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
AddType text/plain .mediawiki
AddCharset UTF-8 .mediawiki .txt
# https://httpd.apache.org/docs/current/mod/mod_mime.html
IndexOptions Charset=UTF-8 +FancyIndexing NameWidth=*
DefaultIcon /images/icons/filetypes/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/doc.svg .doc
AddIcon /images/icons/filetypes/dox.svg .docx
AddIcon /images/icons/filetypes/htm.svg .htm .html
AddIcon /images/icons/filetypes/ico.svg .ico
AddIcon /images/icons/filetypes/jpg.svg .jpg .jpeg
AddIcon /images/icons/filetypes/med.svg .mediawiki
AddIcon /images/icons/filetypes/mht.svg .mht .mhtml
AddIcon /images/icons/filetypes/ods.svg .ods
AddIcon /images/icons/filetypes/odt.svg .odt
AddIcon /images/icons/filetypes/oxp.svg .oxps
AddIcon /images/icons/filetypes/pdf.svg .pdf
AddIcon /images/icons/filetypes/png.svg .png
AddIcon /images/icons/filetypes/svg.svg .svg
AddIcon /images/icons/filetypes/txt.svg .txt
AddIcon /images/icons/filetypes/xht.svg .xht .xhtml
AddIcon /images/icons/filetypes/xls.svg .xls
AddIcon /images/icons/filetypes/xlx.svg .xlsx
AddIcon /images/icons/filetypes/xml.svg .xml
AddIcon /images/icons/filetypes/xps.svg .xps
AddIcon /images/icons/filetypes/zip.svg .zip
IndexOptions +IconsAreLinks
ReadmeName /footer.htm
# https://httpd.apache.org/docs/current/mod/mod_autoindex.html
# Apache Hypertext Transfer Protocol Server Access (HTACCESS) for Nicole Sharp's Website: https://www.nicolesharp.net/
# Copyright (C) 2026-04-14 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