I have some old URLs in a forum application points to http://mydomain.tld/showthread.php?p=xxxx where xxxx is the an integer id.
My new forum application uses viewtopic.php?p=xxxx and I want to handle this using IIS web.config rewrite rules.
I have tried to add the last rule as the following:
<rewrite>
<rules>
<rule name="Redirect www to non www" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="http://domain.tld/{R:1}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.tld" negate="true" />
</conditions>
</rule>
<!-- this for change from showthread.php to viewtopic.php -->
<rule name="Rewrite" stopProcessing="true">
<match url="(.*)showthread\.php" />
<action type="Rewrite" url="viewtopic\.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
However, it does not able to redirect to the viewtopic.php. Any suggestion?
I have to enable httpRedirect in the IIS. Then I used this redirect rule in the web.config at the root of my forum:
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*showthread.php" destination="/viewtopic.php?$P" />
</httpRedirect>
Related
I have this iis site for which I have added some rewrite rules.
The rewrite rule itself is simple If I access the site www.a.com rewrite/redirect to www.b.com
and redirect subpages to corresponding subpages on www.b.com
So have via IIS manager setup some rewrite rules.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match l=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" l="https://{HTTP_HOST}{REQUEST_I}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="https://shop.a.com/5e/ -> https://www.b.com/products/5/" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/5e/" />
<action type="Redirect" l="https://www.b.com/products/5/" logRewrittenl="false" />
</rule>
<rule name="https://shop.a.com/5e/ -> https://www.b.com/products/5/" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/5e/" />
<action type="Redirect" l="https://www.b.com/products/5/" logRewrittenl="false" />
</rule>
<rule name="https://shop.a.com/10e/ -> https://www.b.com/products/10/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/10e/" />
<action type="Redirect" l="https://www.b.com/products/10/" logRewrittenl="true" />
</rule>
<rule name="https://shop.a.com/16e/ -> https://www.b.com/products/16/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/16e/" />
<action type="Redirect" l="https://www.b.com/products/16/" logRewrittenl="true" />
</rule>
<rule name="https://shop.a.com/3e/ -> https://www.b.com/products/3/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/3e/" />
<action type="Redirect" l="https://www.b.com/products/3/" logRewrittenl="true" />
</rule>
</rules>
</rewrite>
prior to this I had a rewrite that rewrote shop.a.com to www.b.com
This one should not be active anymore, but for somereason is this still active, and all the other rules listed here does not seem to work.
When I access shop.a.com/5e I enter www.b.com.
The network tab in chrome states that the url is being redirected to www.b.com, but have no idea where this redirect is listed if not in the web.config?
the url mentioned here are only examples and not the actual sites being managed.
Any idea on why this redirect is doing this?
I used regex match instead which made it work.
The exact matching via iis did not work as expected.
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 want to redirect a page in Azure web.config with the url:
http://example.com/Vad+%E4r+V%E4rdskap__1053.html
to
http://example.com/what-is-welcoming/
I'd like it to work for http://www.example.com as well.
I tried adding my own rule in web.config with the following code:
<rule name="URL1" stopProcessing="true">
<match url="^Vad\+%E4r\+V%E4rdskap__1053\.html" ignoreCase="true" />
<action type="Redirect" url="/what-is-welcoming/" redirectType="Permanent" />
</rule>
I also tried without escaping the + signs.
There were some issues but I managed to solve the problem.
The first issue was a security setting for + signs in URL:s for ISS.
This was solved by using:
...
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
The code for the matching and redirect were as follows:
<rewrite>
<rules>
<rule name="vadarvardskap" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com/Vad+%E4r+V%E4rdskap__1053.html" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.example.com/Vad+%E4r+V%E4rdskap__1053.html" />
</conditions>
<action type="Redirect" url="http://example.com/what-is-welcoming/" redirectType="Permanent"/>
</rule>
...
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 want add a rewrite rule to IIS 7 rewrite.
I want to redirect a user from page
http://localhost/myapp/register.html to http://localhost/myapp/register/register.html
And similar for other pages.
Any help?
Can I do the same using a rewrite action?
Using IIS7 and Windows Server 2008.
Thanks.
I'm not sure if it suits your needs but you can try this one (and maybe make some small adjustments if the case):
<system.webServer>
<rewrite>
<rewriteMaps>
<rewriteMap name="Register Redirect">
<add key="register.html" value="/register/register.html" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Redirect rule1 for Register Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^(.*)/register/(.*)(\.html)?$" negate="true" />
</conditions>
<action type="Redirect" url="{HOST}/register/{R:1}" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>