0
votes

I have a MediaWiki installation hosted in IIS10. I am attempting to use the URL Rewrite module to remove the namespace prefix from some MediaWiki article URLs.

  • In MediaWiki, articles outside the "Main" namespace show as foo.com/wiki/Namespace:Article_Title
  • I only need to remove the 'Bar:' Namespace prefix, others can remain intact
  • Restriction: I am unable to move these articles into the Main namespace

The desired result would present content from foo.com/wiki/Bar:Article_Title but display as foo.com/wiki/Article_Title.

Existing Inbound URL Rewrite

I have one URL rewrite already in place, per Microsoft's doc for MediaWiki on IIS, which removes the query string from the url. Here is my rewrite rule based on that guidance:

            <rule name="Clean-WikiArticlePages" stopProcessing="false">
                <match url="^wiki/(.*)$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="/w/index.php?title={UrlEncode:{R:1}}" />
            </rule>

What I've tried so far

I've tried both an Inbound and Outbound rule, to no effect.

Inbound rule:

            <rule name="Clean-Namespace" enabled="true">
                <match url="^wiki/(Meetings:)(.*)" />
                <action type="Rewrite" url="/wiki/{R:2}" />
            </rule>

Outbound rule:

        <outboundRules>
            <rule name="Remove-Namespace" preCondition="IsHTML" enabled="true">
                <match filterByTags="A" pattern="^wiki/Bar:(.*)" />
                <action type="Rewrite" value="/wiki/{R:1}" />
            </rule>
            <preConditions>
                <preCondition name="IsHTML">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules> 
1

1 Answers

0
votes

I think it is possible to achieve this if you only want to rewrite for Bar. You want the URL displayed as foo.com/wiki/Article_Title and load content from /wiki/Bar:Article_Title?

Then you should redirect all /wiki/Bar:Article_Title request to foo.com/wiki/Article_Title. Then rewrite foo.com/wiki/Article_Title back to /wiki/Bar:Article_Title request.

But please keep in mind this only work for static namespace. Because the rewritten request unable to get the namespace of original request before redirection.

Not sure if below rules achieve your requirement When you access

foo.com/wiki/Bar:Article_Title ------redirect----->foo.com/wiki/Article_Title -------rewrite------> foo.com/wiki/Bar:Article_Title-------rewrite---->foo.com/w/index.php?title=bar%3AArticle_Title

                <rule name="redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="^/wiki/bar:Article_Title$" />
                    </conditions>
                    <action type="Redirect" url="wiki/Article_Title" redirectType="Temporary" />
                </rule>

                <rule name="rewrite">
                    <match url="^wiki/Article_Title$" />
                    <action type="Rewrite" url="wiki/bar:Article_Title" />
                </rule>

  <rule name="Clean-WikiArticlePages" enabled="true" stopProcessing="true">
                <match url="^wiki/(.*)$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="/w/index.php?title={UrlEncode:{R:1}}" />
            </rule>