Manual:Short URL/Apache/zh

These instructions help setup Short URLs on Apache. The LiteSpeed webserver is Apache compatible and can be configured in relatively the same way. For information on what Short URLs are or to get instructions on configuration for other servers see. If you don't know what webserver you're using since you're using some sort of web hosting service, it's very likely that your host is using Apache.

计划
开始之前，你需要决定你的虚拟"短链接"的路径.

在本说明中，我们假设使用如下格式，记住在应用到你自己的部署中，他们可能会不同.


 * MediaWiki的安装目录在：
 * 使用的短链接格式是：

下面的说明已被写入到自动向导中(需要MediaWiki1.17或更高版本）


 * shorturls.redwerks.org

如果您只是想快速配置您的wiki，或者您发现该指南令人困惑，那么您可能需要先尝试该工具. 但请注意，它不适用于设有防火墙或私人部署的wiki. 在后一种情况下，您仍然可以通过将 设置为 来使您的wiki暂时公开来尝试. 一旦完成，请记得将其更改为.

否则，请继续.

找到正确的文件
在Apache中设置短URL的推荐方法是编辑Apache配置文件. 这要求您可以访问服务器配置. 如果您在共享主机上，则很可能受到限制，并且需要使用 文件. 但它们足够强大以设置大多数短网址配置. LiteSpeed用户应该使用 方法.

使用以下两个部分之一中的说明，具体取决于您是否具有root访问权限或需要使用.

找到Apache配置文件（root访问权限）
The correct configuration file to edit for root configurations may be in one of a number of places.

Most linux distributions setup Apache with set of  and   folders setup. The correct config file to edit is the one in  where the configuration for your wiki has been setup. If you haven't set one up and are using the default  for your wiki setup then you can edit.

Don't forget to enable overrides by. It is disabled by default in Ubuntu 12.04 and Ubuntu 12.10.

If your distribution does not have those directories, then you should edit the Apache configuration file directly. This file should be at. Note that it used to be named, if you have a   and no   then   is the one you want to edit.

If your Apache config isn't in any of these spots you should consult the documentation for whatever system you used to install Apache, and find the location of the Apache configuration file.

If you're on a shared host without access to Apache config files you'll have to use a .htaccess file instead.

In an Apache config file you will likely have a VirtualHost block containing your wiki. If you do have one then that is the location where your rewrite rules will go. RewriteRule config does not inherit so don't put these config options in the global config if you are using a VirtualHost.

After you've setup the config as above inside Apache you're going to need to restart Apache to make it apply the new config.


 * If you are using Plesk or cPanel it should have a method of restarting the server.
 * From the command line the command is usually something like,  ,   or as on the latest Fedora releases  . These commands need to be run as root, usually by prefixing them with.

Where to put .htaccess
If you're using a  file you'll need to edit or create the file. Find the path that contains both your script path and your virtual path. Usually this means the top directory of your site, but let's look at a few examples:

Note that if you want to make a redirect from the main domain to your wiki's Main Page (e.g. http://example.org/ http://example.org/wiki/Main_Page ). Then you always have to set up the .htaccess file in the top level, even if the other directories are nested deeper.

Setting up the rewrite rules
It's easier to understand the rest of this section after a glimpse at the Apache syntax, but this synopsis is not a substitute for the full Apache documentation:

The  directive defines a condition that must be true before a RewriteRule that follows it may be applied. One or more RewriteCond directives may precede a RewriteRule directive, and all the RewriteCond directives that precede a RewriteRule must be true before that rule may be applied to a URI. In the examples that follow,  takes the form of a reference to server variables, e.g.  . Although many   exist, the examples that follow use   (true when TestString is a regular file) and   (true when TestString is a directory), and they are preceded by a negation symbol,.

The  directive may be invoked in both the   file and in any   file, but when the rewrite rule appears in .htaccess files, the implicit per-directory context affects the rule's   because rules are relative to the current directory. In  files, Patterns are not relative to the complete, original URI. For  files, Patterns should never start with a forward slash, , because the URI sub-string will never begin with a. The examples that follow use the  flag whose meaning is Stop the rewriting process immediately, and don't apply any more rules.

The first rule you'll need inside of your config is one to enable the rewrite engine:

Now we need a rule to make your article path a virtual path pointing to index.php. Be sure to replace  and   with the paths you choose in the beginning (if different).

If you are using a root url instead of a normal short url you will need to use the following instead (to ensure that existing files and directories are not seen as article, e.g. " " " " etc.):

Sometimes, the above example doesn't work. The following (you can't set this in a, you need root access for this!) might work instead:

Optionally, you can include a rule to show the Main Page on the path itself, to simplify navigation when people visit urls without a page title specified:

The end result should look something like this:

or, if you used the way with the "Alias" statement:

LocalSettings.php
We need to make the following configurations in :

If you get an "Internal error" page saying "Redirect loop detected!" after you finish configuration you may be using something other than mod_php. If so you need to explicitly turn on short urls using the following line in your LocalSettings.php:

If there is still an "internal error" check the log files of your server. Maybe you have to turn on  module.