I have used web.config to redirect the url to a different website but after i remmove the line of code that redirects, the changes do not reflect and when i access the website i still get an redirect.
I have tried to restart the AppService plan but that does not work.
How can I change everything back as it was?
the code below i have written:
<rule name="[RULE NAME]" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="[OLD URL]" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[OLD URL]" />
</conditions>
<action type="Redirect" url="http://[NEW URL]" redirectType="Permanent"/>
</rule>
You had a Permanent redirect. That will result in a HTTP 301 code, which in most normal circumstances will be cached.
It may help to clear your browser's cache. Or try a different browser.
See How long do browsers cache HTTP 301s?.
Related
We have a bunch of websites hosted in IIS using Flex. There are quite a lot of Rewrite/Redirect rules for each of them. One of them now needs a Rewrite rule to direct a non-www url to a www url. Have already tried quite a few popular solutions from various sites including other SO question. The last I tried is as following, without much to avail:
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^your.domain.name$" />
</conditions>
<action type="Redirect" url="http://www.your.domain.name/{R:0}" redirectType="Permanent" />
</rule>
Ensure you have the latest URL Rewrite extension.
https://www.iis.net/downloads/microsoft/url-rewrite
Before testing the result, please clean the local cache. We had better verify it in an inprivate window.
Besides, Failed Request Tracing is a powerful tool for troubleshooting request-processing failures. FRT can be used with the URL rewrite module to trace how rewrite rules were applied to the request URL.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules
At last, please try the below configuration.
<rule name="Force www" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com{REQUEST_URI}" />
</rule>
Feel free to let me know if the problem still exists.
I'm new to the world of IIS in terms of redirects and have been tasked with setting up a redirect for a portion of our site.
The URL I need to redirect is brandview.auditedmedia.com and I need it
to go to https://auditedmedia.com/data/media-intelligence-center/brand-view
The trick is we can have a URL with a QueryString such as
brandview.auditedmedia.com/memberNumber=423524 and that URL should NOT
be redirected.
Also, the scheme of brandview.auditedmedia.com does not matter. Both
HTTP and HTTPS should redirect.
So I'm not sure should I be doing this in IIS or as a RouteMap in the app?
If I should be doing this in IIS can someone point me to either an article or give an example of what I need to do?
Thanks
Bob
You need to add URL rewrite rule on the server level. Use conditions to prevent redirection for requests with non-empty query string string.
For your case it is necessary to add the following rule:
<rule name="brandview redirect" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^brandview\.auditedmedia\.com$" negate="false" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" appendQueryString="false" redirectType="Permanent" />
</rule>
There is detailed instruction on your question. Note, the rule must be created in system.webServer/rewrite/globalRules section of %windir%\system32\inetsrv\config\ApplicationHost.config file.
I got the pattern fixed (see below) and though all the pattern matching works properly in URL Rewrite Module (using test button and putting in different URLs), it still isn't working properly when I attempt to go to the site. The server just continues with serving the page and not redirecting.
<rewrite>
<globalRules>
<rule name="brandview redirect" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(https?:\/\/)?brandviewdev\.auditedmedia\.com$" negate="false" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" redirectType="Permanent" appendQueryString="false" />
</rule>
</globalRules>
</rewrite>
Also you can add URL rewrite rule using GUI. Before you start make sure that both of the direct HTTP-requests to brandview.auditedmedia.com and https://auditedmedia.com/data/media-intelligence-center/brand-view returns status 200 (OK).
Open IIS Manager by prompting inetmgr command.
Select brandview web site in the Connections pane and open URL Rewriting feature.
Create new empty rule using Add rule(s)... action.
Within the Edit Inbound Rule dialog, enter the following:
Name: Redirect to auditedmedia.com;
Requested URL: Matches the Pattern;
Using: Regular expressions;
Pattern: .*;
Action type: Redirect;
Redirect URL: https://auditedmedia.com/data/media-intelligence-center/brand-view.
Append query string: false;
Redirect type: See Other (303);
Save the rule by clicking Apply on the Actions pane.
Make sure that request to brandview.auditedmedia.com will be redirected to https://auditedmedia.com/data/media-intelligence-center/brand-view.
Repeat steps 1, 2 and select Redirect to auditedmedia.com rule.
Execute action Add condition(s)... with following:
Condition input: {QUERY_STRING};
Check if input string: Does Not Matches the Pattern;
Pattern: .+;
Ignore case: true.
Push OK button.
As result, all requests to brandview.auditedmedia.com with empty query string will be redirected to https://auditedmedia.com/data/media-intelligence-center/brand-view page. After testing you can change redirect type to 301.
After trying different combinations I finally got the redirect to work correctly and to be honest, I'm not sure how. Here is my config
<rewrite>
<rules>
<rule name="Brandview Redirect" enabled="true" stopProcessing="true">
<match url="^$" ignoreCase="true" negate="false" />
<action type="Redirect" url="https://auditedmedia.com/data/media-intelligence-center/brand-view" appendQueryString="false" redirectType="Temporary" />
<conditions>
<add input="{HTTP_HOST}" pattern="brandviewdev\.auditedmedia\.com" />
<add input="{QUERY_STRING}" pattern=".+" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
I have a Joomla site on Azure. I have set up the .com properly and I understand why the *azurewebsites.net URL is still working.
I wanted to redirect all traffic from *azurewebsites.net to the .com. I followed this guide and it works as intended.
http://onthecloud.azurewebsites.net/seo-tip-how-to-block-the-.azurewebsites.net-domain
However, I also have an Azure CDN in place (mycdn.azureedge.net/). I use JCH Optimize to set up the CDN. I see the the calls to mycdn.azureedge.net/ are generated properly. However, somehow, because of the web.config redirect, all the traffic is redirected from the CDN back to my .com, which defeats the purpose of the CDN. This creates a lot of redirect calls.
Is there a way to write the web.config lines to exclude the CDN?
Here's what my web.config looks like. When I delete those lines, the CDN redirects disappear, so the problem is really here.
<rule name="Disable Azure Domain" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
<action type="Redirect" url="http://www.example.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
Look at your conditions. You're filtering all traffic that goes to "*.azurewebsites.net". All calls to your cdn fall into that filter as well, which is why you're seeing them be redirected:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
Instead, filter the calls just to your website. So your condition would look more like:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="yoursite.azurewebsites.net" />
</conditions>
That'll let calls to the CDN go through just fine.
You can find more details on setting up redirect rules for your Azure Web App here: http://zainrizvi.io/2016/04/07/block-default-azure-websites-domain/
Fyi, below is the full web.config that I use for my site. You'll not that I've set some of the other settings a bit differently. Try using that web.config file instead (just change the site names as appropriate) and see if it works for you.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to zainriziv.io" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^zainrizvi\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.zainrizvi.io/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Note: When you're testing the fix your browser might have cached the redirect, so you might want to try fiddler or a new browser/pc to verify things work as expected
I need to redirect all https requests to http, for example, if someone visits https://www.example.com/another-page/ to http://www.example.com/another-page/
I have the following rewrite rule in my web.config right now, but it's not working correctly. It's redirecting https://www.example.com/another-page/ to https://www.example.com/, so to the root of the site, but instead I want the redirect to stay in the same URL and only rewrite https to http.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{R:1}" pattern="^onepage/(.*)$" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
Any help on changing the above rule so that it only changes https to http, but keeps the full url visited would be greatly appreciated!
I set up your rule, cleaned up a little, and it worked; so this isn't really answering with much new.
Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment.
Also, try changing the action to {R:1} instead of {R:0}. It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. R:0 means the entire matched string, which always confuses me just a little.
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
One possibility is that your browser has cached a previous attempt of your rules. When the redirectType is Permanent, and you're still developing or testing, the browser often caches a previous rule. Clear your browser cache, and/or remove the Permanent, and/or browse in incognito mode. When done testing, change it to permanent. See number 2 and 3 in this answer: https://stackoverflow.com/a/9204355/292060
Please paste the below code in web.config file.
<rule name="Redirect to http" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
I'm trying to rewrite some urls and i've done this in the past but for some reason it just won't stick this time. Here's the rule:
<rule name="Force HTTPS - Test.aspx" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Templates/Test\.aspx" />
<conditions>
<add input="{HTTP_HOST}" pattern="^my\.domain\.com$" />
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://my.domain.com/Templates/test.aspx" />
</rule>
It should be taking http://my.domain.com/Templates/test.aspx and redirecting to https://my.domain.com/Templates/test.aspx.
Unfortunately it's not working at all, no matter what i try....
I figured out that IIS was configured to force SSL on the files I tried redirecting. That meant it would return an HTTP 403 error before even checking the url rewrite rules.
Hope that helps someone else.