Manual:Short URL/wiki/Page title -- Windows with IIS7--root access

From MediaWiki.org
Jump to: navigation, search

Pretty URLs with Windows IIS7/7.5[edit]

  1. Install IIS URL Rewrite Module
  2. Modify LocalSettings.php
  3. Create a Rewrite/Redirect rule

Install IIS URL Rewrite Module 2.0[edit]

  1. Download appropriate 32bit or 64bit IIS Rewrite Module from Microsoft:
  2. Install on the host server by running the downloaded .msi file

Modify LocalSettings.php[edit]

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;

Create an Inbound and Outbound rule set[edit]

  1. Open Internet Information Services Manager
  2. Select your wiki site from the website list
  3. Open the URL Rewrite Control from the IIS group
  4. Click on "Add Rule(s)..."
  5. Select the "User-Friendly URL" template
  6. Enter http://www.example.com/wiki/index.php?title=Main_Page
  7. 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
  8. Check both of the following options:
    • Create corresponding redirect rules
    • Create corresponding outbound rewrite rule
  9. Click OK
  10. Open the web.config file that appears in the site root directory
  11. Change the following
    • FROM: <match url="^([^/]+)/?$" />
    • TO: <match url="^(wiki/[^/]+)/?$" />
  • rules based on IIS7.5

Sample Web.Config[edit]

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=([^=&amp;]+)$" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                </rule>
                <rule name="Rewrite User Friendly URL" enabled="true" stopProcessing="true">
                    <match url="^(wiki/.+)$" /> <!-- or more strict: <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=([^=&amp;]+)$" />
                    <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>

Mediawiki 在windows iis7下短路径实现[edit]

因为我不会英文,所以请看到的朋友帮我进行翻译一下,一定要翻译一下,因为上面所提供的方法并不能使用,至少我本地及网络测试都失败了。如搜索功能无法匹配。

而我下面提供的新方法,在mediawiki1.25上测试成功:

LocalSettings.php底部加入:

$wgArticlePath = $wgScriptPath . "/$1";
  • 新建web.config,并在里面写入(web.config需要安装Url_Rewriter支持):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="MediaWiki">
                    <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={UrlEncode:{R:1}}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
  • 使用后如果上传图片时出错则要将(我的没有出现这种情况):
<match url="^(.*)$" />

改为

<match url="\.(php|html|gif|jpg|png|css|js)$" ignoreCase="false" />
  • 使用后:首页、内容页、列表页、搜索功能、特殊页面、图片显示等都显示正常。

Iis UrlRewriter特殊字符链接导致404错误解决方法[edit]

UrlRewriter默认设置存在特殊字符404错误问题,我已将文章发在了我的网站上,如果翻译人员看到后,也可将文章转到这儿来,我不会维基文章发布方面的规则。

如果URL中有+(加号)等特殊符号会导致404错误,我们将解决方法写在了:Iis UrlRewriter特殊字符的链接解决方法 文章中。

大家可以将自己的web.config内容进行修改,以解决这个问题。