File htaccess

From mw.mh370.wiki
Jump to navigation Jump to search


A Guide to Using MediaWiki in a Hosted Environment

An instructional website by the developer of mh370wiki.net - a MediaWiki site about Malaysia Airlines Flight MH370.


htaccess = Hyper Text Access

Hidden files and directories name(s) begin with a period . for example .htaccess

.htaccess

A text file named .htaccess (with no file extension) is placed in the root directory of a MediaWiki installation, typically to enable use of Short URLs.

The .htaccess file contains directives which are obeyed by the web server.

On hosted websites the user does not normally have access to the web server configuration files, so directives in the .htaccess file are used instead.

The syntax used in a .htaccess file is complicated. A link to documentation from apache.org is provided below. It could be supplemented by other Internet resources.

Most MediaWiki users initially just follow examples from MediaWiki documentation and only customise configuration after growing more confident.

/w Directory

For the directives in MediaWiki-supplied example(s) of .htaccess it is imperative that the MediaWiki installation be in a /w directory.

A hosting provider usually uses a directory /public_html for websites and adds a subdirectory such as /www.mysite.net when a new domain is added. This becomes the root directory for the website and is the directory which will typically have the subdirectory /w, the .htaccess file, a robots.txt file, a sitemap file, and verification keys for search engines.

The MediaWiki installation in /w has the standard MediaWiki structure with a LocalSettings.php file, and subdirectories for extensions, images and code.

URLs

The default page URL for a MediaWiki-based webpage includes an unwanted path /w/index.php?Title= and the goal is to make that 'pretty' or 'short' by substituting the default path with /wiki.

Two articles explain this in more depth:-

  1. Short URL - covers the common process for rewriting /w/index.php?Title= as /wiki
  2. Short URL for .wiki Domain - covers the special case of a MediaWiki-based website with a top-level domain .wiki, such as this website. To avoid a URL with .wiki/wiki the .htaccess file and configuration in Localsettings.php must be different from option 1.

.htaccess Examples

  1. Comments

    The web server will ignore lines beginning with the # character.

  2. Deny directory listing

    By default, if an accessible directory does not have an index.html file then the directory contents can be listed in a web browser.

    Add this line Options -Indexes to a .htaccess file in that directory to prevent file listing.

    Preventing listing does not prevent browsing, if someone knows or tests for file names.

  3. Require all

    Several subdirectories in a standard MediaWiki installation have a .htaccess file which looks like this:-

    Require all denied
    Satisfy All
    

    This syntax is an update of the Allow or Deny (below)

    Require all denied prevents external access and returns an http status code 403 (Forbidden).

    Satisfy All Apparently this may be a default server setting, but in case the server configuration was Satisfy Any, the inclusion of Satisfy All ensures that all of the allow / deny conditions will be met, not just some or any of them. In this MediaWiki instance Satisfy All ensures that the condition Require all denied is not optional.

  4. Allow or Deny

    Web browsing within a directory can be denied to All, or denied to specific IP addresses. Conversely, browsing can be allowed.

    The order (Allow, Deny) or (Deny, Allow) is often inserted as a comment. Some options are:-

    • Deny from All - denies web browsing from all external sources:- Deny from All

    • Deny from a specific IP Address - Deny from nnn.nnn.nnn.nnn

    • Deny All but allow a specific IP Address:
      #Order Deny, Allow
      Deny from All
      Allow from nnn.nnn.nnn.nnn
      
    • Deny directory listing and browsing - add these lines to a .htaccess file in the directory:-

      Options -Indexes
      Deny from All
      



    Articles which relate to .htaccess file

    Articles which relate to .htaccess file are included in Category:File htaccess.

    The CategoryTree Extension enables a listing of relevant sub-categories and pages:-



    Links

    Manual:Short URL/wiki/Page Title -- .htaccess
    https://www.mediawiki.org/wiki/Manual:Short_URL/wiki/Page_Title_--_.htaccess
    Manual:Short URL
    https://www.mediawiki.org/wiki/Manual:Short_URL
    Apache HTTP Server Tutorial: .htaccess files
    https://httpd.apache.org/docs/current/howto/htaccess.html
    .htaccess Customizations
    https://help.dreamhost.com/hc/en-us/sections/203242107--htaccess-Customizations
    A very useful article from the Dreamhost Knowledge Base.