Manual:Short URL/wiki/Page title -- Windows with IIS7--root access
|
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. |
Contents |
[edit] Pretty URLs with Windows IIS7/7.5
- Install IIS URL Rewrite Module
- Modify LocalSettings.php
- Create a Rewrite/Redirct rule
- Create an Inbound and Outbound rule set
- Sample web.config
- Basics of Creating IIS Rewrite/redirect rules
[edit] Install 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
[edit] Modify LocalSettings.php
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;
-
[edit] Create an Inbound and Outbound rule set
- Open IIS Network Manager
- Select your wiki site from the website list
- Open the URL Rewrite Control from the IIS group
- Click on "Add Rule(s)..."
- Select the "User-Friendly URL" template
- Enter http://www.example.com/wiki/index.php?title=Main_Page
- Select http://www.example.com/Main_Page from the drop down
- There IIS Rewrite template doesn't support customizing through this window, we will get to a clean up step
- Check both of the following options:
- Create corresponding redirect rules
- Create corresponding outbound rewrite rule
- Click OK
- Open the web.config file that appears in the site root directory
- Change the following
- FROM: <match url="^([^/]+)/?$" />
- TO: <match url="^(wiki/[^/]+)/?$" />
- rules based on IIS7.5
[edit] Sample Web.Config
This is a sample web.config file that contains rules based on the above. There is a second entry other then the rules. The httpRedirect handles making sure that any request to: http://www.example.com/ is directed to http://www.example.com/wiki/. This allows mediaWiki to pick up and run with any additional redirects.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect User Friendly URL" enabled="true" stopProcessing="true"> <match url="^wiki/index\.php$" /> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern="^title=([^=&]+)$" /> </conditions> <action type="Redirect" url="{C:1}" appendQueryString="false" /> </rule> <rule name="Rewrite User Friendly URL" enabled="true" 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="wiki/index.php?title={R:1}" /> </rule> </rules> <outboundRules> <rule name="Outbound Rewrite User Friendly URL" preCondition="ResponseIsHtml1" enabled="true"> <match filterByTags="A, Form, Img" pattern="^(.*/)wiki/index\.php\?title=([^=&]+)$" /> <action type="Rewrite" value="{R:1}{R:2}/" /> </rule> <preConditions> <preCondition name="ResponseIsHtml1"> <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" /> </preCondition> </preConditions> </outboundRules> </rewrite> <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent"> <add wildcard="/" destination="/wiki/" /> </httpRedirect> </system.webServer> </configuration>