Simple question. I need to redirect all http 80 and https 443 requests on a specific subdomain URL to an alternative SSL port https 444.
Example: http://sub.corp.com --> https://sub.corp.com:444
Example: https://sub.corp.com --> https://sub.corp.com:444
I only wish to use IIS 7.5 URL Rewrite module.
Thanks.
The following URL rewrite rule should do what you want:
<rewrite>
<rules>
<rule name="Redirect to port 444" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^ON$" negate="true" />
<add input="{SERVER_PORT}" pattern="^444$" negate="true" />
</conditions>
<action type="Redirect" url="https://sub.corp.com:444/{R:0}" />
</rule>
</rules>
</rewrite>
It redirects to https://sub.corp.com:444 whenever HTTPS is not ON or when the port number is not 444. The site should have bindings to port 80 (with HTTP), 443 (with HTTPS for standards SSL) en 444 (with HTTPS) for this to work.
Marco's solutions works fine, in case somebody is wondering how to apply this in IIS.
you add this to the web.config file. If you create a Virtual Directory in IIS the selected physical folder will have a web.config created.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to port 50443" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^ON$" negate="true" />
<add input="{SERVER_PORT}" pattern="^50443$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}:50443/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Related
I'm working on updating the stripe checkout from a website, I was doing it successfully on localhost but when I put it on live mode on a windows server it stopped working. The issue is that when I should be redirected to the checkout page from stripe, the url is altered and becomes something that doesn't make sense:
The correct url: www.checkout.stripe.com/pay/cs_...
The url that I get redirected to: www.mysite.com/pay/cs_..
I kept thinking what could be the causa of that and I think it's the URL rewrite rule that I have on the windows server. I would like to add an exception to the rule and allow the stripe checkout to initiate, but I have no idea how to do it.
Below is my web.config file:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8008/{R:1}" />
</rule>
<rule name="HTTPS" enabled="false" 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>
I figured it out. This is my final web.config
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="false" />
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://localhost:8008/{R:1}" />
</rule>
<rule name="stripe redirect in checkout" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="/pay/" />
</conditions>
<action type="Redirect" url="checkout.stripe.com{REQUEST_URI}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
My issue was not really understanding the meaning of the options in the URL Rewrite. I checked the course URL Rewrite for Developers and it was really helpful. I was able to solve the issue quickly.
The file you have shown contains the inbound rewrite rules only. But you have an issue with response from your server. Thus, you should fix the outbound rewrite rule in the right config file.
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.
This rule seems to work fine, but when I go to https://www.example.com it doesn't remove the www.
However, if I go to http://www.example.com it works as expected.
Why is it not redirecting from https?
<rewrite>
<rules>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$"/>
</conditions>
<action type="Redirect" url="https://example.com{PATH_INFO}" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
Per my comment above, your rule actually worked for me in the scenario that you described. However, I do not think that it handles the case when a request is made to an insecure url that does not contain www in the hostname. For example, http://example.com/blah/ would not be redirected. The following rule below handles that case as well:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Remove WWW and Ensure HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://example.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The rule checks for a hostname starting with www or an insecure request. If either condition is met, the user is redirected.
My site is hosted on IIS, I need to enforce the browser to use www prefix.
I've installed the Url Rewrite Module and my rule is:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Add WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
from IIS7 URL Rewrite - Add "www" prefix
But I cannot work out how to maintain ssl
You need to capture the protocol in the input:
<rule name="Enforce WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>
{C:1} will contain the protocol and {C:2} will have your domain and anything else.
(source)
I have a widows machine hosted by goddady and I need to create a rule to forward any request with a URL pointing to a non-existing file to be sent to the index.php.
Usually I would do that with the .htaccess but its different in windows hosts.
I found the answer.
I had to put a xml file named 'web.conf' in the root directory, it works in the same way .htaccess does.
I took the rules from ZendFramework Site
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}"
matchType="IsFile" pattern=""
ignoreCase="false" />
<add input="{REQUEST_FILENAME}"
matchType="IsDirectory"
pattern=""
ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^.*$" />
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This rules will make the server check if the file exsists and if it doesn't then the request is forwarded to index.php