Can I configure IIS to route traffic to another server? - wordpress

I have a Windows server available at website.com, and I have another server with a WordPress on it.
How can I configure IIS to route website.com/blog to my WordPress?
I tried to use virtual directories, but I can only send my user to the same server.

According to your description, I suggest you could consider using ARR reverse proxy to achieve your requirement.
I suggest you could install the ARR by using this link and this link.
Then I suggest you could try to use below url rewrite rule.
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="/blog/(.*)" />
<action type="Rewrite" url="http://ec2 ubuntu address/{R:1}" />
</rule>

Thank you,it worked but I had to add more code to my web.config.
My web.config:
<rewrite>
<rules>
<clear />
<rule name="Route the requests for Company1" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="https://blog.raczum.com/{R:0}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="Route the subfolder blog" enabled="false" patternSyntax="Wildcard" stopProcessing="false">
<match url="https://raczum.com/blog/*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="https://blog.raczum.com/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule> </rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true" stopProcessing="false">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://blog.raczum.com/(.*)" />
<action type="Rewrite" value="/blog/{R:2}" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
</rule>
<rule name="RewriteRelativePaths" preCondition="ResponseIsHtml1" enabled="true" stopProcessing="false">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://blog.raczum.com/(.*)$" negate="false" />
<action type="Rewrite" value="/blog/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1" patternSyntax="Wildcard">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="*" />
</preCondition>
<preCondition name="ResponseIsHtml2">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>

Related

web config rewrite rule to force http to https on multi tenancy application

i have a multi tenancy portal system but the rewrite rule is not working on multiple conditions
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTPS1}" pattern="^(website1\.com|www\.website1\.com)$" />
<add input="{HTTPS2}" pattern="^(website2\.com|www\.website2\.com)$" />
<add input="{HTTPS3}" pattern="^(website3\.com|www\.website3\.com)$" />
<add input="{HTTPS4}" pattern="^(website4\.com|www\.website4\.com)$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
I expect That when i visit http://portal.website1.com on my webs browser, that the program should take me to https://portal.website1.com and to do the same for portal.website2.com, portal.website3.com,portal.website4.com
but it only works for portal.website2.com and portal.website3.com , it does not force https on portal.website1.com and portal.website4.com
Try this in system.WebServer:
<system.webServer>
....
<rewrite>
<rules>
<rule name="Force HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URO}" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>

URL Rewrite 500.52: Unrecognized element 'serverVariables'

I need to implement a reverse proxy using only my web.config and I'm having trouble with the 500.52 error. As suggested in many places online, I added the serverVariables section to include the HTTP_ACCEPT_ENCODING variable, but I am met with an error:
Config Error Unrecognized element 'serverVariables'
Below is my web.config.
<rewrite>
<allowedServerVariables>
<add name="HTTP_ACCEPT_ENCODING" />
</allowedServerVariables>
<outboundRules>
<rule name="reverseProxy">
<match pattern="http://linkInCode.com"></match>
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" value="https://linkIWant.com/script.js"></action>
</rule>
</outboundRules>
</rewrite>
What is the problem? ServerVariables should be a recognised element.
You need to have the server variable registered previously in <allowedServerVariables>,
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-20-configuration-reference#Allowed_Server_Variables_List
Using this blog post, I copied the examples given and changed sections for my needs.
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="https://URLtoHide.com" />
</rule>
</rules>
<outboundRules>
<rule name="Rewrite to clean URL" preCondition="IsHTML">
<match filterByTags="A" pattern="http://http://URLtoShow.com" />
<action type="Rewrite" value="https://URLtoHide.com" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>

Wordpress behind ARR proxy - JSON request not signed

Using IIS ARR I have a reverse proxy to a WP blog hosted elsewhere on a Linux server.
These are the proxy rules:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/blog/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Reverse proxy to blog" stopProcessing="true">
<match url="^(.*)" />
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
<action type="Rewrite" url="http://111.22.33.444/blog/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="Add application prefix" preCondition="IsHTML" stopProcessing="true">
<match filterByTags="A, Form, Img, Link, Script" pattern="^http://111.22.33.444/blog/(.*)" />
<action type="Rewrite" value="https://www.example.com/blog/{R:1}" />
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
</rule>
<preConditions>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
</preCondition>
<preCondition name="IsHTML">
<add input="{HTTP_HOST}" pattern="111.22.33.444" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
<add input="{URL}" negate="true" pattern="wp-admin/" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
"wp-admin/" has been excluded from the IsHTML pre-condition as this was causing redirect loops in some areas of the admin.
The plugin Jetpack has been installed but this is failing to connect to Wordpress.com. Wordpress.com shows the error "There was an error retrieving your site settings." Looking at the errors in Plesk where the blog is actually hosted we see the URL below failed with a 400 bad request.
blog/?rest_route=%2Fjetpack.................
If this URL is called manually in a web browser, it gives the message "The request is not signed correctly".
Can anyone offer any advise on resolving this bad request issue please?

ASP.NET Postback error under Reverse Proxy with IIS 8.5, URL Rewrite 2.0 and ARR 3.0

I would like to setup a reverse proxy in IIS but in my configuration I get problems with ASP.NET postbacks. When you click on any submit button of the proxied website then you get a 404 error. The URL in browser address bar is changed to the rewritten URL.
For example, the website that I need to proxy is http://website.com/host. Here http://website.com and http://website.com/host are separate web applications. Host is running as a virtual folder under website.com.
I want to access the Host from this URL: http://me.local/myhost. In IIS me.local is an asp.net web application and Myhost is added as another application as child of me.local. Everything works just fine as long as you don't click on submit button anywhere on the proxied website. Once you do this then you get to page http://me.local/host which results in 404 error. When you look at page's html source then form's action url is set correctly to /myhost
Why does the error happen? Is it possible to fix it in IIS, or do we need to make changes to the host application?
My server is running IIS 8.5. The host server is an old one with IIS 6, and web application can be asp.net 1.1 or asp.net 2.0.
The section with rewrite rules from web.config of "myhost" application is:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Route the requests for host" stopProcessing="true">
<match url="^(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://website.com/host/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="hostToDefault" stopProcessing="true">
<match url="^" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="default.aspx" appendQueryString="false" />
</rule>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^(.*)default\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="(.*)" appendQueryString="false" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://website.com/(.*)" />
<action type="Rewrite" value="/{R:2}" />
</rule>
<rule name="NonhostRewriteRelativePaths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(?!host)(.*)" negate="false" />
<action type="Rewrite" value="http://website.com/{R:1}" />
</rule>
<rule name="hostRelativePaths" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/host/(.*)" negate="false" />
<action type="Rewrite" value="/myhost/{R:1}" />
</rule>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*)myhost/default\.aspx$" />
<action type="Rewrite" value="{R:1}/myhost/default" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<urlCompression doStaticCompression="false" doDynamicCompression="false" />
</system.webServer>
</configuration>

url rewriting in iis7

I am running IIS7.5 and the URL Rewrite module.
I followed these step by step instructions to enable user friendly URL's:
Rule Templates for the URL Rewrite Module - User Friendly URL - rule template
If I enter the URL http://domain.com/default/ instead of http://domain.com/default.aspx the website throws 404: file not found error.
Here are my rewrite rules:
<rewrite>
<rules>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^demourl\.dev\.asenetechdev1\.com/default\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="demourl.dev.asenetechdev1.com/default"
appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^demourl\.dev\.asenetechdev1\.com/default$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
</conditions>
<action type="Rewrite" url="demourl.dev.asenetechdev1.com/default.aspx" />
</rule>
</rules>
<outboundRules>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img"
pattern="^(.*)demourl\.dev\.asenetechdev1\.com/default\.aspx$" />
<action type="Rewrite" value="{R:1}/ demourl.dev.asenetechdev1.com/default" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
I also tried using Intelligencia.UrlRewriter with this. But I am able to generate friendly urls on local as well as on server, but I want extensionless url, which is working ok on my local server, but not on the live server.
Your pattern is currently not matching /default/. It is only matching /default
Changing
<match url="^demourl\.dev\.asenetechdev1\.com/default$" />
to
<match url="^demourl\.dev\.asenetechdev1\.com/default/{0,1}$" />
should do it.

Resources