I want to redirect a particular url to another server. Following is my rewrite rule:
<rewrite>
<rules>
<rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(http|https)(://domain1\.)(example\.)(com|net)(/research)(.*)" />
<action type="Redirect" url="{R1}://{R3}{R4}/domain1research" />
</rule>
</rules>
</rewrite>
I am expecting that if a user types https://domain1.example.com/research, they should be redirected to https://example.com/domain1research. I've tested the expression with multiple variations on the url (.com, .net and query string) and it matches always. But when I run the website it never gets re-directed to the other page. I've URL rewrites in many web apps and they all work fine. I am not able to put my fingre on what I'm missing here.
I have tried it locally with an entry in hosts file and in a published website (Asp.Net MVC) on Azure but nothing works.
As per #lex Li's blog post and Microsoft documents, following rewrite works:
<rewrite>
<rules>
<rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
<match url="research" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(domain1\.)(example\.(com|net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/domain1research" />
</rule>
</rules>
</rewrite>
Related
I have set up an Azure App Service to use Virtual Directories.
The path my-app.azurewebsites.net/api is working correctly with the site wwwroot/api.
I have a CNAME record for api.mydomain.com to my-app.azurewebsites.net which works just fine as well. I can successfully call api.mydomain.com/api.
However I'd like to use a subdomain instead of the path, rewriting api.mydomain.com to api.mydomain.com/api
I've added a web.config file in my wwwroot directory which looks like following now
wwwroot/
- api/
- web.config
web.config:
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^api.mydomain.com$" />
</conditions>
<action type="Redirect" url="https://api.mydomain.com/api/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
After a restart, the App Service is not responsive and does not serve requests anymore. Is there a better way to achieve this or do I need to modify my rewrite?
After a few attempts I figured the mistake. Redirect has to be changed into Rewrite.
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.mydomain.com$" />
</conditions>
<action type="Rewrite" url="api/{R:1}" />
</rule>
</rules>
</rewrite>
I have been trying to creat an IIS Rewrite rule that looks at the incoming Header for an API and if it contains a certain string re-direct them to a certain page and not the API (Noobs - Using documentation API Keys)
Been at it 2 hours and just can't work it out. Could anyone help?
Thanks
Finally Got it! Here is teh rule below for anyone else that is interested.
<rewrite>
<rules>
<rule name="Rewrite Noob Documentation API Key" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_Authorization}" pattern="^ukvd-ipwhitelist ABCD1234-1b3d-4d63-aa75-ABCDEF123456$" />
</conditions>
<action type="Redirect" url="https://xxx.co.uk/dockey.html" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I need to redirect from
http://someserver/someapplication.page.aspx
to
http://someserver.domain.com/someapplication.page.aspx
Both the requests lead to the same server.
someserver/ works through our company's internal DNS
This is the same question as Redirecting to Full Domain
but I want an IIS solution for this, not code. My guess is it will have something to do with adding a httpRedirect add element in Configuration Editor using wildcards.
You can use URL Rewrite for that which is the recommended way to do it in IIS, simply add a web.config with a rule like:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to full domain" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^someserver$" />
</conditions>
<action type="Redirect" url="http://someserver.domain.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I've seen several blogs and questions which I believe match what I'm doing, but it's not working. URL Rewrite module is installed. I'm resetting IIS after I save this web.config file. I've tried using IIS's GUI as well with same results. Is there something else I'm not aware of?
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.us$" />
</conditions>
<action type="Redirect" url="http://www.domain.us/{R:0}" />
</rule>
</rules>
</rewrite>
Ok, I forgot to add the binding domain.us to the site. Woops!
I'm trying to set the canonical URL for my site (macton.com) to add the www in the beginning. The site is hosted using IIS and I installed the URL Rewriter Extension.
Here is the code I put in the web.config file. However, it doesn't seem to do anything, because it remains macton.com.
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^macton\.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.macton.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
After this I have a bunch of <location> tags with redirects that work fine. I tried using a redirect from macton.com → www.macton.com but that just creates an infinite redirect loop (DUH!)
Any idea why this wouldn't be working? Everywhere I look says this is the correct code!
This link can help:
http://www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7
Have you also added macton.com to the binding of your website?