Redirect directory to Azure url - redirect

I have written this rule in webconfig to redirect all my resources in thsi folder to my azure blob but it is not showing any image there.
<rule name="RewriteIncomingCdnRequest" stopProcessing="true">
<match url="^/CDN/(.*)$" ignoreCase="false"/>
<action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:0}" />
</rule>
http://sttest.azurewebsites.net/CDN/image_cdn-trans.png
this should redirect to azure storage....
image url on storage
https://stplatformstorage.blob.core.windows.net/static/image_cdn-trans.png

you have a bad regular expression - as written, url="^/CDN/(.*)$" would only match /CDN/image_cdn-trans.png - because "^" means "from start of..." -- what you really need is url="^.*/CDN/(.*)$" and then use the matching group {R:1} - for:
<rule name="RewriteIncomingCdnRequest" stopProcessing="true">
<match url="^.*/CDN/(.*)$" ignoreCase="false"/>
<action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:1}" />
</rule>
The URL Rewrite module has a great test function to test your regular expressions.

Related

Web.config Redirect to new site, with and without params

We have pulled out some code of our monolith, and build a separate application (With it's own url) instead. We need to be able to redirect links hitting the old monolith application new application.
Old url: https://OldApp.domain.com/OldAppContoller/123
New url: https://NewApp.domain.com/NewAppController/123
So when users go to the old url either with, or without the 123 id it should redirect to the new app.
Also if I'm running the Old application locally I need it to redirect direct it to our test environment "t-" like this:
Old url: https://localhost:7777/OldAppContoller/123
New url: https://t-NewApp.domain.com/NewAppController/123
And lastly I need to grab the environment prefix t,m,p to redirect to the correct environment.
I've been messing around with the web.config, but haven't found a working solution yet.
Here is what I've got:
<system.webServer>
<rewrite>
<rules>
<rule name="NewApp Localhost with Param" stopProcessing="true">
<match url=".*localhost.*OldAppContoller\/([0-9]*)"/>
<action type="Redirect" url="https://t-NewApp.domain.com/NewAppController/{r:1}" redirectType="Permanent" />
</rule>
<rule name="NewApp Localhost without Param" stopProcessing="true">
<match url=".*localhost.*OldAppContoller"/>
<action type="Redirect" url="https://t-NewApp.domain.com/" redirectType="Permanent" />
</rule>
<rule name="NewApp with Param" stopProcessing="true">
<match url=".*OldApp-([a-z]).*OldAppContoller\/([0-9]*)"/>
<action type="Redirect" url="https://{r:1}-NewApp.domain.com/NewAppController/{r:2}" redirectType="Permanent" />
</rule>
<rule name="NewApp without Param" stopProcessing="true">
<match url=".*OldApp-([a-z]).*OldAppContoller"/>
<action type="Redirect" url="https://{r:1}-NewApp.domain.com" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm not sure if this is to be done with one rule, or multiple rules as my example above.
Any suggestions ?

IIS Web.config Rewrite rules - Redirect rules with - or + chars

https://someserver.com/path01/2011/abc+and+def/88722
https://someserver.com/path01/2011/abc-and-def/88722
I have several URLs that I need to create a redirect rule. I need to remove "2011" from the url and change the URL... I got most of it working but I can't figure out how the "-" or "+" needs to be written and how to combine into one rule
<rule name="Redirection 1" stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc-and-def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:2}#/abc-and-def"/>
</rule>
<rule name="Redirection 2" stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc+and+def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:2}#/abc-and-def"/>
</rule>
I tried to use this use rule but it's not working !!
<rule name="Redirection rule " stopProcessing="true">
<match url="test-catalog/([0-9]*)//abc([-+]*)and([-+]*)def/([0-9]*)"/>
<action type="Redirect" url="https://someserver.com/path01/overview/{R:4}#/abc-and-def"/>
</rule>
Any ideas on how to solve this issue?

IIS redirect rule not working

<rule name="Directories The" stopProcessing="true">
<match url="^Directories/The" />
<action type="Redirect" url="/" />
</rule>`
I have two url like this www.mydomain/Directories/the and www.mydomain/Directories/the-hindu. But i only want to redirect first url only. If i put above code two urls are redirecting.
I tried with exact match and wild card also not working. I dont want www.mydomain/Directories/the-hindu to my home page
`
The problem is that your regexp ^Directories/The is matching for both URLs:
www.mydomain/Directories/the
www.mydomain/Directories/the-hindu
You need to add the end of string condition to your regexp. The correct rule should be:
<rule name="Directories The" stopProcessing="true">
<match url="^Directories/The$" />
<action type="Redirect" url="/" />
</rule>`
And this rule will match only www.mydomain/Directories/the

web.config rewrite complete URL

Hi there,
Just a simple question. I Have a Domain with path, let's say exampleme.com, and this page has a specific page: exampleme.com/game.php. Is there a way to completely rewrite the link to another domain on that page? So that exampleme.com/game.phpbecomes game.com?
I've tried this, but since I'm fairly new to the web.config rewrite module, I'm a bit clueless.
` <rule name="Examplerule">
<match url="http://game.com" ignoreCase="false" />
<action type="Rewrite" url="/game.php" appendQueryString="false" />
</rule>`
Rewrite works only on your current domain. You need an redirect.
<rules>
<rule name="Game" stopProcessing="true">
<match url="/game.php" />
<action type="Redirect" url="http://game.com" />
</rule>
</rules>

IIS rewrite rule to redirect specific domain url to different url on same domain

I simply want an IIS 7.5 rewrite rule to redirect http://www.domain.com/url1 to http://www.domain.com/url2 (same domain). This can be achieved by:
<rule name="Redirect url" enabled="true" stopProcessing="true">
<match url="^url1" />
<action type="Redirect" url="http://www.domain.com/url2"
appendQueryString="false" redirectType="Permanent" />
</rule>
However, this website listens to several domains, thus above becomes a global rule for all domains. How do I make this specific to domain.com? Have tried changing match url and adding conditions but cannot get it to work. Thanks.
I got it to work this way:
<rule name="Redirect url1" stopProcessing="true">
<match url="^url1$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/url2"
appendQueryString="false" redirectType="Permanent" />
</rule>
Using the answer on this page, I was able to tweak a rule for myself. I also added query parameters. Wanted to post it here, in case it helps someone:
<!-- probably requires custom rewrite module, available through web platform installer -->
<rule name="Redirect oldsite.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
</conditions>
<action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&mode=form"
appendQueryString="false" redirectType="Permanent" />
</rule>
Some bits of explanation:
To clear up some confusion, this "url" is the part after the first slash after the domain, and not the whole url. I'm going to put in this so that it gets any URL.
<match url=".*" />
Now, we'll add a condition because I had more than one web site on this computer, so I want to make sure this rule is applied to only one of them. I also used the wildcard instead of "(www.)?" because the wildcard will catch any subdomain.
<conditions>
<add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
</conditions>
And the last note is for folks who want to put multiple query string params in. You'll need to escape the ampersand between them, because it won't work if you don't:
<action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&mode=form"
appendQueryString="false" redirectType="Permanent" />