手册:缩短URL/IIS8.5

From mediawiki.org
This page is a translated version of the page Manual:Short URL/IIS8.5 and the translation is 81% complete.

在 Windows Server 2012 + IIS 8.5 + PHP 5.6 环境下对 Mediawiki 1.26 进行短网址设置。

必要条件

首先需确保搭建的 Mediawiki 站点在正常运行,并且 Mediawiki 安装到除 /wiki 以外的路径。 比如安装在 /w 目录。 这样就可以通过 http://www.mysite.com/w/index.php?title=Main_Page 的形式在你的wiki站点浏览和编辑文章。

修改 LocalSettings.php 文件

编辑 LocalSetting.php 文件中对应的配置项:

$wgScriptPath = "/w";        # 可能已经存在
$wgArticlePath = "/wiki/$1"; # 向MediaWiki告知IIS如何重写URL
$wgUsePathInfo = true;

创建重写规则

创建或编辑在网站根目录下的 web.config 文件,一般是 C:\Inetpub\wwwroot (不在 /w 目录下)。 写入以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^wiki/([^/]+/?[^/]*/?[^/]*)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="w/index.php?title={R:1}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Redirect visitor of your domain to your wiki

Our official guides for short url configuration include recommendations on how to point the root of your site to your wiki using your short url config.

To do this in IIS add the following to your web.config.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="RootHitRedirect" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="/w/" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>