Manual:Short URL/IIS7
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. IIS version 7 was released in 2008 and saw its end of life in 2020. |
Warning: This Short URL page contains bad advice on how to configure your server that could lead to some pages on your wiki not working and/or may cause you issues while upgrading. This guide remains simply because an official guide on how to configure short URLs on this wiki has not been created yet. |
Generic Tutorial on IIS Rewrite Module
[edit]The following tutorial offers a number of articles to describe the IIS Rewrite module: Using URL Rewrite Module. IIS.net also has a tutorial on setting up MediaWiki on IIS, including an overview of "Enabling clean URLs with URL Rewrite Module": MediaWiki on IIS
Using the IIS URL Rewrite Module with MediaWiki
[edit]The following steps were performed to successfully integrate the IIS URL Rewrite Module with the Short URL capability offered by MediaWiki using Windows 7 or 2008 Small Business Server and IIS 7.0:
- Install the IIS URL Rewrite Module 2.0:
- Download appropriate 32bit or 64bit IIS Rewrite Module from Microsoft:
- (x86): 32bit Rewrite Module from Microsoft (Version 2: download)
- (x64): 64bit Rewrite Module from Microsoft (Version 2: download)
- Install on the host server by running the downloaded .msi file
- Download appropriate 32bit or 64bit IIS Rewrite Module from Microsoft:
- Create a rewrite rule:
- Open the Internet Information Services (IIS) Manager
- Select the site that contains the MediaWiki installation
- Select "URL Rewrite" within the IIS Area group features
- Right click "URL Rewrite" icon. Select, "Open Feature"
- Click "Add Rules..." (on the right-hand "Actions" panel)
- Select "Blank Rule" and click "OK" (displays the Edit Rule pane)
- Enter a unique name for the rule (e.g.
WikiShortURLStd
) - Set the "Requested URL" drop down to "Matches the pattern"
- Set the "Using" drop down to "Regular Expressions"
- Enter
^wiki/(.*)$
in the "Pattern" field -- no leading slash (i.e. "wiki/" not "/wiki/"!) - Don't add any conditions
- Set the "Action Type" drop down to "Rewrite"
- Enter
w/index.php?title={R:1}
in the "Rewrite URL" field- (Where
w
is the http document path of your MediaWiki installation (e.g. www.example.com/w))
- (Where
- Leave the "Append query string" check box as checked
- Press Apply (on the right-hand "Actions" panel)
- Edit the appropriate path configurations in your LocalSettings.php file:
- $wgScriptPath = "/w"; # The directory under your document root where MediaWiki is installed
- $wgArticlePath = "/wiki/$1"; # This is the rewritten URL
- $wgUsePathInfo = true;
Additional Info
[edit]For those using the above settings and experiencing problems with special pages (or any with the ':' (colon) character in them) try using the following in the "Rewrite URL" field "w/index.php?title={UrlEncode:{R:1}}"
If your wiki is installed in the root of your website (www.example.com/index.php?title=...), w is nothing. Use "/index.php?title={R:1}" in the "Rewrite URL" field.
Subdomain Wiki Uses
[edit]For those interested in using subdomains with their account, you must create a different regular expression within IIS. Instead of using the ^wiki/(.*)$ pattern match. You must use ^[a-zA-Z_0-9/:\-]*$ or something extremely close to this. CSS wasn't working with the above method, so switching to this regular expression helped greatly.
GoDaddy IIS7 Hosting Notes
[edit]Since GoDaddy has shared hosting of IIS7, you will not be able to use the IIS management console to enter the URL rewrite parameters. Fortunately GoDaddy has installed the URL rewrite module already, so all that is left for you to do is to upload a web.config file to your wiki root folder.
The below example is the entire contents from the web.config used successfully to mimic the effect detailed by the ".htaccess" file mentioned in the main Short URL article:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wikiRule1" stopProcessing="true">
<match url="^wiki/(.*)$" />
<action type="Rewrite" url="/fubuwiki/index.php?title={UrlEncode:{R:1}}" />
</rule>
<rule name="wikiRule2" stopProcessing="true">
<match url="^wiki/$" />
<action type="Rewrite" url="/fubuwiki/index.php" />
</rule>
<rule name="wikiRule4" stopProcessing="true">
<match url="^/*$" />
<action type="Rewrite" url="/fubuwiki/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Alternative
[edit]The code below has been used successfully on IIS7 on Windows Server 2008, with PHP 5.2.1.2 and MediaWiki 1.15.1 using the URL Rewrite Module, Friendly URL writer:
<rewrite>
<rules>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^index\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" />
<add input="{QUERY_STRING}" pattern="^title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?title={R:1}" />
</rule>
</rules>
</rewrite>
Note: Make sure you either switch to source view before copying the code into your web.config file. The QUERY_STRING pattern above contains an ampersand, which will not get copied correctly unless you switch to source view. In XML string literals, an ampersand is properly represented as the ampersand character followed immediately by the text "amp;" (not including the quotes). If you do not switch to source view and you copy the above code as is, IIS 7 will generate a 500.19 error with the message that the configuration data is invalid due to malformed XML.