Manual:Short URL/zh


 * 以下的一些资料可能会过时或不正确. 如果你熟悉以下的内容，请尝试帮助我们更新这篇文章. 

万维网的发明者蒂姆伯纳斯-李曾经说过，良好的网页URL地址应该永远保持不变. 隐藏了复杂的程序代码的网页地址能给访客一个好的体验. 在开始之前，请花几分钟时间为您的网站制订一个稳定的网址结构，以减少以后一些不必要的麻烦. 为了阅读方便，这个页面已经被分成独立的章节，下面有目录.

默认配置
MediaWiki的默认安装路径一般都是下面这样:
 * (用Root账户安装)
 * (虚拟主机安装)

MediaWiki的默认页面地址一般是下面这样：
 * (最新版本的Mediawiki, 没有使用CGI)
 * (最新版本的Mediawiki, 使用了CGI)

使用下面将提到的方法, 我们可以把地址设置成下面的样子:
 * ( 标准形式，像Wikipedia那样的)
 * (不建议采用！)

好处与坏处
Long URLs have a key advantage: they work in all hosting environments — a good thing to know lest one day you move your wiki to a hosting environment where you can't keep using the same URLs everyone has bookmarked or linked to.

The advantages of short URLs are that they hide all technical details, as is best practice for URLs – among other things this means they can be kept stable when the underlying mechanism change, if your hosting environment supports this. They are also easier for visitors to remember and allow visitors to navigate the site by URL more conveniently.

Once you've decided that you really want short URLs and are willing to go through the effort, you're ready for the long trial and error configuration as detailed below.

Shared hosting
Most shared hosting systems do not allow changes to httpd.conf. If you are using a shared host, first try asking your hosting provider who may well solve your problem for you. If that doesn't work out, depending on your hosting provider, you may be able to edit .htaccess (detailed below).

If you have a choice, you should edit httpd.conf (which requires root access and is the preferred method because your wiki will perform better ). You only need to edit either .htaccess or httpd.conf, not both.

建议的配置步骤（以 Wikipedia 的配置为例）
The following setup is used on Wikipedia, and tends to be robust and easy to set up. This setup should be used unless you really dislike some aspects of it (it doesn't rewrite all URLs) or you simply can't use it (it requires root access).

好处

 * This method is reliable and guaranteed to work in all versions of MediaWiki for the indefinite future. Other schemes are not tested by MediaWiki developers and might break when changes are made to the software.
 * Not all URLs are rewritten, but this is good. With a single simple rule, this allows you to easily block search engine spiders from viewing background pages (like the edit form or history pages), separate actual article views from other accesses in log analysis, et cetera. Although links to edit pages and background pages are slightly less memorable, this is no big deal: the important thing is the articles.
 * The method uses Alias instead of Rewrite. This is simpler and more reliable.

坏处

 * This method requires Apache and root access.

配置步骤
First of all, ensure that you are using Apache and have root access (so you can modify httpd.conf; modifying .htaccess is not enough!). If either of these is false, you cannot use this exact method; you need to modify it appropriately, or use some other method listed below, preferably Manual:Short URL/wiki/Page title -- no root access.

In case you earlier chose /wiki/ as your folder for installing MediaWiki unknowingly, then rename the folder name to new name (here /w/</tt>) and replace /wiki/</tt> with new path (here /w/</tt>) wherever you see it (one typically only needs to change  file). 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. If you're using a localized version of MediaWiki (non-English) the names of the Special pages will be translated. Check the actual links in your wiki for the special page URLs. These are independent of the personal language choice of individual users.
 * 1) Find the directory in which your wiki was installed. By default, this is a subdirectory called /w, within your web server's document root (web root). The web root is the directory where you put all the html files that your web server makes publicly available. For instance, if your web root is /var/www, then your wiki is probably in /var/www/w. Inside this directory you should see files like index.php and LocalSettings.php. This can all be a little confusing, because on some systems (e.g., Debian), the subdirectory /w may actually be a symbolic link (e.g., to /usr/share/mediawiki/).
 * 2) Choose a virtual directory in which you want your articles to appear. This guide will assume that you choose /wiki/</tt> (as Wikipedia does), articles will then be accessed like  http://www.example.com/wiki/Article_title </tt>. 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/</tt> folder relative to your web root as Wikipedia does, and not in /wiki/</tt> folder.
 * 1) In LocalSettings.php</tt>, modify with the following:   Note that   should already be set to /w</tt>. If it is not (for example, if you're moving from a different URL scheme), make sure to set it to that.
 * 2) Edit httpd.conf</tt> to contain the rule  . Note that the second path is relative to the filesystem root, not the web root! This might be, for instance, , if /var/www/</tt> is your web root.  If this does not work or you get a 403 error, use an absolute path that begins with the drive MediaWiki is installed on such as  .  This ALIAS configuration is a minimum configuration, see Apache configuration for further options.  If you're using Apache 2, the configuration file is called apache2.conf. If you don't have a httpd.conf</tt>, then use this.
 * 3) Make Apache reread its configuration file (gracefully restart). You might use, for instance,   or a similar command as root, or use features of WebHost Manager or similar software.</li>  If you're using Apache 2, the command is apache2ctl graceful.
 * 4) In your web root, create a file called robots.txt</tt> if one does not already exist.  Then add the following to the end of the file:    The first "Disallow" rule stops spiders from indexing histories, edit pages, and other background pages that are useless to users performing a search. This will also prevent duplicate content from being indexed. The second and third rules stop spiders from indexing two special pages that might confuse them, and generally be unhelpful.

You're done; your wiki should be working perfectly. If not, go to irc://irc.freenode.org/mediawiki and report any problems.

其他方式的缩写配置
Anyone is welcome to create a how-to solution page and list it below. Please use a sensible name for the page, one that fits in with the below names. When each unique solution has its own page, readers can skip complexity they do not want. Keep it simple, readable, short, with a separate page per separate solution.

To help others find out which Short URL methods really work, after trying each method please edit the page and increase the "worked" or "didn't_work" numbers for that guide and make a brief (or long, your choice) description on what went wrong by clicking the link on your number.

URL 示例： example.com/wiki/Page_title
How to create example.com/wiki/Page_title</tt> URLs: - recommended method if you don't have root access; should also work with PHP as CGI mode

Root access

These methods require that you have access to the server configuration. If you are on a shared host, you most likely don't; see the "no root access" examples instead.

(If the Alias method is not suitable [for example, you use PHP as a CGI], you can use Apache instead.)

URL 示例： example.com/Page_title
How to create example.com/Page_title</tt> URLs: 

(used this method: x2) (also works with 1.10 & 1.13, but not with 1.11., very similar to the above solution)

URL 示例： wiki.example.com/Page_title
How to create wiki.example.com/Page_title</tt> URLs.

(the above enhanced, work with 1.14)

Ampersand (&) problem
The ampersand problem shows up when you have page titles with symbols in (such as &, ?, #, + and /) that, despite being correctly encoded in the link are not being passed correctly from mod_rewrite to the script. This manifests in 404 page-not-found errors, because the title gets cut off at the special character. For example, clicking on a link to "John & Maria's page" gets a 404, because MediaWiki is looking for a page named "John ".

This is because ampersands in long-form names are treated as query string separators, and would never reach the PHP runtime environment. This is caused by an old and problematic mod_rewrite bug. There are discussions of other possible solutions at lists.wikimedia.org and fgiasson.com.

Solutions:

Looping alias/rewrite errors
If you receive looping alias/rewrite errors such as "Cannot find page www.example.com/wiki/wiki/wiki/wiki/wiki/ [...] /index.php", try one of these fixes:

No Skins
With Ubuntu 8.10 and Mediawiki 1.11.2 (and maybe later versions) if you use the Mediawiki sanctioned directions your skins may fail to load. To fix this, create a symbolic link in /var/www pointing to /var/lib/mediawiki with the value of $wgScriptPath in LocalSettings.php. If, for example, $wgScriptPath is set to "/w" then you need to run the command "sudo ln -s /var/lib/mediawiki /var/www/w".

Revert to default
If you need to revert to the default values of your wiki but have accidentally deleted them, here are the defaults:

Redirect visitor of your domain to your wiki
Drop a <tt>index.php</tt> file in your web root directory with the following lines: