I created an IIS rewrite role for a server url.
When I send request to [https://mysite/back/api/....][1], it will get data from https://remotesite/back/api/....
So my IIS rewrite config is like following.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="api">
<match url="^api/(.*)" />
<action type="Rewrite" url="`https://remotesite/back/api/{R:1}`" />
</rule>
</rules>
<outboundRules>
<clear />
<rule name="api">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ORIGIN}" pattern="(.*)" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
But the [https://mydomain/back/api/][1] has a "Referrer Policy: strict-origin-when-cross-origin". So I can not send a javascript request to my domain.
How can I update the config?
You can use the IIS CORS module to solve this problem. For information about "IIS CORS module Configuration Reference", you can refer to this link.
Related
They changed the url rewrite Module version (URL Rewrite Module 2.1) and now the redirection from http to https is not working.
Has anyone encountered the same problem?
Application : Angular
System : Windows Server IIS 10
This is the web.config file (it was working for the earliest version of URL rewrite : urlrewrite2.exe)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions applyToWebDAV="false">
<add fileExtension=".pdf" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
<directoryBrowse enabled="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks.
For http://example.com:80 to https://example.com:443 your rule posted in the question is correct and working fine on my side.
If it is not working on your side, you could check the Failed Request Tracing logs might give you the information about the issue. The issue might be something else.
For http://example.com:81 to https://example.com:443, you could refer to the rule below.
<rule name="Redirect with port" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.*):81$" />
</conditions>
<action type="Redirect" url="https://{C:1}:443/{R:0}" />
</rule>
Output:
Let me know if you have further questions.
I am using URL rewrite to redirect all incoming request to my node.js app.
It works fine.
However, I want to redirect
http://www.example.com
to
https://www.example.com
I have googled the related setting.
Although, it can display the node.js web app correctly, however, the browser report that is not a secure web site.
Here is my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="forward rule" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://localhost:9000/{R:1}" />
</rule>
<rule name="http to https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://www.example.com" />
</rule>
</rules>
</rewrite>
<httpRedirect enabled="false" destination="https://www.example.com/" exactDestination="false" childOnly="true" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
I found that if I don't bind HTTP to the web site, it will prompt error.
There are 2 applications running on local network:
host headers:
http://ui.local, http://api.local
On another server, a website is already setup for url rewriting. Host header of the site is http://externalui.mydomain.com
Here is web.config contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://ui.local/{R:1}" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
This url rewriting rule is running without a problem and rewrites all URLs made to http://externalui.mydomain.com to go to http://ui.local
However i want to write another rule so requests made to http://externalui.mydomain.com/api/.... will be forwarded to http://api.local/api/... instead.
How to write a rule for this condition?
You could use the below rule:
<rule name="redirect api" stopProcessing="true">
<match url="api/(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="http://api.local/api/{R:1}" />
</rule>
<rule name="all redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Redirect" url="http://ui.local/{R:1}" />
</rule>
Note: make sure the API rule should be the first rule.
How can I match the root url and redirect it to index.html?
I have tried:
<rule name="SPA">
<match url="^$" />
<action type="Rewrite" url="index.html" />
</rule>
and
<rule name="SPA">
<match url="" />
<action type="Rewrite" url="index.html" />
</rule>
in Azure App Service.
But they didn't work. I got: Cannot GET /
my Web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA">
<match url="^$" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I tried Redirect as well. But no luck.
<rule name="Redirect to canonical url">
<match url="^$" >
<conditions>
<!-- Check whether the requested domain is in canonical form -->
<add input="{HTTP_HOST}" type="Pattern" pattern="^purchasehelper.azurewebsites.net$">
</conditions>
<!-- Redirect to canonical url and convert URL path to lowercase -->
<action type="Redirect" url="http://purchasehelper.azurewebsites.net/index.html" RedirectType="Found"/>
</rule>
You can try to add and modify the following rewrite content in web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Index Request" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="index.html" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I am looking to use the sub-page link for a website on Azure, for example:
Html file mysubpage.html placed in the wwwroot directory in Azure. I wish to be able to access this page by typing mysite.com/mysubpage into the web browser. However, when I visit this url I get the output "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
I understand that I need to do this with a web.config file in the wwwroot directory, but am unsure as to what contents the web.config file needs to contain?
I currently have the following:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
<rule name="Remove html Extension" stopProcessing="true">
<match url="^(.+)\.html$" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
Solved the issue. The following worked which removed the removal of the html extension:
<?xml version="1.0" ?> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites" defaultValue="">
<add key="/mysubpage" value="/mysubpage.html" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer> </configuration>
I understand that it you want to re-route numerous urls you can do this by adding extra lines with add as follows:
<add key="/mysubpage1" value="/mysubpage1.html" />
<add key="/mysubpage2" value="/mysubpage2.html" />