Manual:Short URL/wiki/Page title -- no root access
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! If you're still having problems after following the steps, take a look at the discussion page, as there are some workarounds for errors which could be introduced.
[edit] Basic setup steps
- Decide what name you want to use for the virtual path in which you want articles to appear.
Note: Do not reuse an existing path name or create a directory by this name!!! The only path that must already exist is where you installed MediaWiki. If you earlier installed MediaWiki into /wiki/, change the name now (/w/ in this example). If you try to ignore this, short URLs will fail.
- Add or edit the following settings in LocalSettings.php to have article links generated by MediaWiki refer to "/wiki/Articlename" instead of "/w/index.php?title=Articlename":
$wgScriptPath = "/w"; # Physical path (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 $wgScriptPath! $wgLogo = "$wgScriptPath/wiki_logo.png"; # May need to be adjusted to where your logo is found.
- If you're using an older version, make sure to put these lines after
otherwise you'll find some settings get overridden. Too late and the wgScriptPath won't affect things like the wgStylePath.
require_once( "$IP/includes/DefaultSettings.php" );
- If you're using an older version, make sure to put these lines after
- Create or edit .htaccess in your web root directory (typically, public_html or htdocs) adding:
RewriteEngine On RewriteRule ^/?wiki(/.*)?$ /w/index.php [PT,L,QSA] RewriteRule ^/*$ /w/index.php [L,QSA]
If you get an "Internal error" page saying "Redirect loop detected!" try setting
$wgUsePathInfo = true;in your LocalSettings.php, your host may be using a setup that MW can't detect as path-info supporting but still supports path-info.If this does not work (i.e. the Apache installation used breaks REQUEST_URI and MediaWiki can't extract the proper data from it), use this older code:
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]
If this does not work (i.e. you have one VirtualHost that responds to requests on wiki.example.org and www.example.org but only want to run MediaWiki on the former), you may have to try something like this instead:
RewriteEngine On RewriteCond %{HTTP_HOST} wiki.example.org RewriteRule ^/?wiki/(.*)$ /w/index.php?title=$1 [PT,L,QSA] RewriteCond %{HTTP_HOST} wiki.example.org RewriteRule ^/?w(/)?(.*)$ /w/$2 [L,QSA] RewriteCond %{HTTP_HOST} wiki.example.org RewriteRule ^/?(.*)$ /w/$1 [L,QSA]
RewriteRule defines virtual paths and how they should be rewritten; in the example above, /wiki/Page will cause /w/index.php?title=Page to be loaded instead.
Note: If there are already RewriteRule entries in your .htaccess file, especially very broad ones, you may need to put the Mediawiki RewriteRule entries immediately after RewriteEngine On, so that the more specific rules are first.
Note: If your host uses something other than .php to identify php files you will need to adjust the rules accordingly.
Note: If you do not want http://example.com/ to redirect to your wiki, remove the last RewriteRule.
Note: If it is not already enabled, you must enable mod_rewrite on your Apache server (or you will have a 500 error).
Note: If /w leads to some other physical location ("symlink" in unix, "shortcut" in windows, "alias" in mac), you must allow Apache to follow by adding to the .htaccess file: Options +FollowSymLinks
[edit] GoDaddy or BlueHost
If you are on GoDaddy or BlueHost 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] Deeper Subdirectory
If you are in a deeper subdirectory, this method still works perfectly well. The following was tested with MediaWiki 1.15.4 on Apache 1.3.34 on FreeBSD 6.3, but is likely to work with later versions just as well.
For example, with the web root at /usr/local/www/data, and a desired wiki URL of the form http://www.example.com/clients/bigclient/Main_Page
Put the wiki code in /usr/local/www/data/clients/bigclientwiki -- that is, somewhere different from where you want it to appear. In this directory, the LocalSettings.php file contains (amongst other things):
... $wgScriptPath = "/clients/bigclientwiki"; $wgArticlePath = "/clients/bigclient/$1"; $wgUsePathInfo = true; ...
Your rewrite code goes in .htaccess in your web root. In this example that would be /usr/local/www/data, but might be a deeper directory (if you have name-based virtual hosting, for example).
The .htaccess contains (possibly with other things):
RewriteEngine On RewriteRule ^clients/bigclient/(.*)$ /clients/bigclientwiki/index.php?title=$1 [PT,L,QSA] RewriteRule ^clients/bigclient/*$ /clients/bigclientwiki/index.php [L,QSA]
| Language: | English • Русский |
|---|