Manual:Short URL/wiki/Page title -- no root access

From MediaWiki.org

Jump to: navigation, search

Contents


These instructions assume you're using Apache and do not have root access. Please read the Recommended guide if you do have root access. You can rewrite URLs, so the server will load "/w/index.php?title=article" for "/wiki/article". The two paths for files and pages (in this example, /w and /wiki), must be different from each other!

[edit] Setup steps

  1. Choose a virtual directory in which you want your articles to appear. This guide will assume that you choose /wiki/ (as Wikipedia does), articles will then be accessed like http://www.example.com/wiki/Article_title. Do not create this virtual directory and it should not exist in the web root folder! This guide assumes that you have installed MediaWiki in /w/ folder relative to your web root as Wikipedia does, and not in /wiki/ folder.
    Note Note: In case you earlier chose /wiki/ for installing MediaWiki unknowingly, then rename the folder name to new name (here /w/) and replace /wiki/ with new path (here /w/) wherever you see it (one typically only need to change LocalSettings.php file).
    Note Note: The install path must not be same as virtual directory and must not be the web root directory itself, the first point is important, do not try to ignore it to get prettier URLs, or else this method will not work.
  2. Add or edit the following setting in LocalSettings.php. This will cause the HTML generated by MediaWiki to refer to "/wiki/Articlename" instead of the default:
    $wgScriptPath = "/w";         # Path to the actual files (right part of first rewrite rule). Should already be in LocalSettings.php
    $wgArticlePath = "/wiki/$1";  # Virtual path (left part of first rewrite rule). MUST be DIFFERENT from the path set above ($wgScriptPath)!
    $wgUsePathInfo = true;
    $wgLogo = "/w/wiki_logo.png"; # You may need adjust that to point where your logo is, without it your logo will disappear
    
  3. Create or edit .htaccess in your web root directory (typically, public_html) adding:
    RewriteEngine On
    RewriteRule ^wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
    RewriteRule ^wiki/*$ /w/index.php [L,QSA]
    RewriteRule ^/*$ /w/index.php [L,QSA]
    

    RewriteRule defines the rewrite; in the example above, /wiki/Page will cause /w/index.php?title=Page to be loaded instead.

    Note Note: If your /w directory is a symbolic link ("symlink") to some other location, you must allow Apache to follow symlinks using the following code in the .htaccess file:
    Options +FollowSymLinks
    
    Note Note: If you do not want http://example.com/ to redirect you to your wiki because you have other things running too, remove the last RewriteRule.
    Note Note: If your host uses something other than .php to identify php files you will need to adjust the rules accordingly.
    Note Note: If your .htaccess seems to have no effect whatsoever, contact your system administrator to fix this problem.
    Note Note: If you want to have some backward compatibility with old syntax (for example, when you decide to use new URL syntax after some time, when there are some links on pages on your wiki over the internet), you can add a simple redirect before other rules: RewriteRule ^wiki/index.php/(.*)$ /wiki/$1 [R,L]
    Note Note: If you want to have full backwards compatibility and make the old URLs with the query redirect to the new URLs, try this:
    RewriteCond %{QUERY_STRING} ^title=(.*)$
    RewriteRule ^/index\.php$ /wiki/%1? [R=301]
    


    OR

    If you are on GoDaddy and hosting multiple-sites:

    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteRule ^hindupedia/en/(.*)$ eng/index.php?title=$1 [PT,L,QSA]
    RewriteRule ^hindupedia/$ eng/index.php?title=$1 [PT,L,QSA]
    

[edit] More Info

Take a look at the discussion page, as there are some workarounds for errors which could be introduced.