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>
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>
Related
I try change the subfolder path (virtual directory) via rewrite module on IIS
I want change the url path from "www.site.com/photos/20/be2f-8ed24a0d1a9a.jpg" to "www.site.com/photos/20_new/be2f-8ed24a0d1a9a.jpg" where "/photos" is virtual directory and "/20" its subfolder
I write rule:
<rewrite>
<rules>
<clear/>
<rule name="photo path rewrite" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="/photos/20/(.*)" />
</conditions>
<action type="Redirect" url="{HTTP_HOST}/photos/20_new/{C:1}" redirectType="Temporary" />
</rule>
</rules>
<rewriteMaps></rewriteMaps>
</rewrite>
What I doing wrong? Thanks:)
Could you explain the URL you want to redirect belong to src attribute or you just want to access the URL directly?
If URL is accessed directly, you just need to change your condition input from {QUERY_STRING} to {REQUEST_URI}.
If this url belong to "src" attribute in the html img tag , then you can try this outbound rule.
<rewrite>
<outboundRules>
<rule name="outbound rule" preCondition="IsImage">
<match filterByTags="Img" pattern="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="/photos/20/(.*)" />
</conditions>
<action type="Rewrite" value="{HTTP_HOST}/photos/20_new/{C:1}" />
</rule>
<preConditions>
<preCondition name="IsImage">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
I'm using IIS 10. I've a website that is reachable with subdomain1.domain.com and subdomain2.domain.com only on HTTPS protocol.
I would like to set up a rewrite rule only if request comes from subdomain2.domain.com where website should load the URL subdomain2.domain.com/la/signin. This last URL should be masked and not showed to the user.
I've tried a lot of rewrite rules and searched other suggestions on stackoverflow but every solutions did not worked for me, even without mask.
This one is just my last try without mask, but I've tried many other solutions:
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="https://subdomain2\.domain\.com$" />
<action type="Rewrite" url="{R:0}/la/signin" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Any other suggestion?
Please try this rule. It will rewrite https://subdomain2.domain.com(/) to subdomain2.domain.com/la/signin.
<rule name="Redirect" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="la/signin" appendQueryString="true" logRewrittenUrl="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="subdomain2\.domain\.com" />
<add input="{HTTPS}" pattern="^on$" />
<add input="{URL}" pattern="^(/)?$" />
</conditions>
</rule>
Will rule #2 get hit if rule #1 does first? Or will it stop at rule #1 for IIS Url Rewrite Module. I am trying to skip webfonts with the specific origin.
<outboundRules>
<rule name="Set Access-Control-Allow-Origin header">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?(thestatbook\.com|localhost:3000)))" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^[^\?]+\.(ttf|otf|eot|woff|woff2|svg)(\?.*)?$" />
</conditions>
<action type="Rewrite" value="*" />
</rule>
</outboundRules>
Will rule #2 get hit if rule #1 does first? Or will it stop at rule #1 for IIS Url Rewrite Module.
As far as I know, both outboundRules wil hit. It will firstly run "Set Access-Control-Allow-Origin header", then "Enable CORS for Fonts". You could write a simple rule to and use postman to test it.
Rule like below:
This rule will modify the Access-Control-Allow-Origin and Server variable.
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
Result:
If you just want only one rule is fired not hit another rule. I suggest you could try to use StopProcessing flag.
It means when the rule action is performed (i.e. the rule matched) and this flag is turned on, it means that no more subsequent rules will be processed and the request will be passed to the IIS request pipeline. By default, this flag is turned off.
Rule like below:
<rewrite>
<outboundRules>
<rule name="removingserverheader" enabled="true" stopProcessing="true">
<match serverVariable="RESPONSE_SERVER" pattern=".*" />
<action type="Rewrite" value="0" />
</rule>
<rule name="Enable CORS for Fonts" enabled="true">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions>
<add input="{HTTP_ORIGIN}" pattern=".*" />
</conditions>
<action type="Rewrite" value="2" />
</rule>
</outboundRules>
</rewrite>
Result:
I have a nodejs application running on iis.
I have url rewrite rule which sends all request to a custom server.js page.
I want to add a new rule or modify the existing one so that a particular url /something reaches the iis and not the rule I have written.
My rule currently:
<rewrite>
<rules>
<rule name="node">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
Please help on this one.
<rule name="sendToNode">
<match url="/*" />
<conditions>
<add input="{URL}" pattern="/something$" negate="true" />
</conditions>
<action type="Rewrite" url="server.js" />
</rule>
I got a problem with the creation of rewrite rule which is using a rewrite map in IIS. The goal is to rewrite requests like /Japan/test.html or /Chile/test.html to jp/en/simple-test and cl/en/simple-test.
Here is the rewrite rule:
<rule name="Rewrite sites" enabled="true" stopProcessing="true">
<match url="^/(.*)/test.html$" />
<conditions>
<add input="{Sites:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}/en/simple-test" appendQueryString="false" />
</rule>
And this is my rewrite map:
<rewriteMap name="Sites">
<add key="chile" value="cl" />
<add key="japan" value="jp" />
</rewriteMap>
So once again, I want to dynamically translate all the languages into language codes and rewrite to language_code/en/simple-test. I want to use rewrite map as there will be more languages.
After few hours of tests, I was finally able to solve my problem. Here is how Rewrite Rule and Rewrite Map should look like for above conditions:
<rule name="Rewrite sites" enabled="true" stopProcessing="true">
<match url="(.*)/test.html$" />
<conditions>
<add input="{Sites:{R:1}}" pattern="(.*)" />
</conditions>
<action type="Rewrite" url="{C:1}/en/simple-test" />
</rule>
<rewriteMap name="Sites">
<add key="chile" value="/cl" />
<add key="japan" value="/jp" />
</rewriteMap>
Tip! If you don't known what is in {R:0}, {R:1}, {C:0} or {C:1} back referenced create fake rewrite action e.g.: <action type="Rewrite" url="www.test.com?a={C:1}" /> and in the a param you will see specyfic back reference content.