Manual:Short URL/IIS8.5

From Linux Web Expert

Revision as of 06:29, 25 February 2024 by imported>Ciencia Al Poder (undo. I don't understand what "using url" means here, and readers won't understand either)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This article will walk through the settings necessary to get Short URLs working on Windows Server 2012, IIS 8.5, MediaWiki 1.26, and PHP 5.6.

Prerequisite check

Ensure that your MediaWiki site is running and accessible at a URL other than /wiki. For this example, we will assume it's running at /w. This means that you can browse, edit articles, etc. on your wiki by starting with http://www.mysite.com/w/index.php?title=Main_Page.

Modify LocalSettings.php

Edit the appropriate path configurations in your LocalSettings.php file:

$wgScriptPath = "/w";        # may already exist
$wgArticlePath = "/wiki/$1"; # tells MediaWiki how IIS will be rewriting URLs
$wgUsePathInfo = true;

Create a rewrite rule

Create or edit the web.config file in the site root directory, usually C:\Inetpub\wwwroot (not under /w). Ensure it contains the following:

<?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>