I have redirects currently set up to go from oldsite.com to newsite.com using a rewrite map. They work except when a parameter is passed through the URL, ex. http://oldsite.com?utm_source=go.wayne.edu&utm_medium=direct&utm_campaign=quick-access&utm_content=, still goes to the old page instead of redirecting to the new page with the parameters, ex. http://newsite.com?utm_source=go.wayne.edu&utm_medium=direct&utm_campaign=quick-access&utm_content=.
Here's my code:
<rule name="Redirects to New Site">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{RelaunchRedirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://newsite.com/{C:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
Still very new to all of this and I can't figure out why the parameters are not passing. I've seen some similar cases on here but haven't been able to get those solutions to work for me.
Any ideas on what I can do to make this work?
You can try to use this URL Rewrite rule:
<rewrite>
<rules>
<rule name="Redirects to New Site" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
</conditions>
<action type="Redirect" url="http://newsite.com{URL}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Feel free to let me know if there are any questions.
Related
I wrote a rule for redirect non-www to www. Now my site goes to http://www.abcd.com.tr www came and that's what I wanted, but whichever page I click on I get to the error page.
My rule code is below;
<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>
For example when I click this link http://www.abcd.com.tr/tr-tr/deneme/test/ page redirect to error page. Also when I use site without www, there was no problem, all page was working.
Please see what I do for one of my projects, with this you are always redirected to a https://www URL.
PS: I have updated the pattern to include your domain name, please update the "pattern" setting for your project and delete the unnecessary bits.
<rule name="Redirect all domain bar azure and actual domain" enabled="true">
<match url="(.*)" ignoreCase="true"/>
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.abcd\.com\.tr|abcd\-live\-fe\-staging\.azurewebsites\.net" />
</conditions>
<action type="Redirect" url="https://www.abcd.com.tr/{R:1}" redirectType="Permanent" />
</rule>
This will work:
<rule name="Redirect NONWWW to WWW " stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.azurewebsites.net$" />
</conditions>
<action type="Redirect" url="https://www.example.azurewebsites.nyc/{R:0}" redirectType="Permanent" />
</rule>
I Know this has been asked a lot but I just can't seem to figure out how to get this to work, even looking at other variables.
I need to redirect www.example.com/article-2 to www.example.com/article
<rule name="Redirect Dup Artivcle URL" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}{REQUEST_URI}" pattern=" https://www.example.com/article-2/" />
</conditions>
<action type="Redirect" url="https://www.example.com/article/" appendQueryString="false" />
</rule>
I feel like I may have the wrong URL matching pattern...
Its obviously that {HTTP_HOST} is not covering https://.
Please modify the rule like this
<rule name="Redirect Dup Artivcle URL" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.example.com/article-2/" />
<add input="{HTTPS}" pattern="^on$" />
</conditions>
<action type="Redirect" url="https://www.example.com/article/" appendQueryString="false" redirectType="Temporary" />
</rule>
I have a URL in the format:
https://www.example.com/aaa/bbb/product/~productId=abc123
Which I would like to redirect to:
https://www.example.com/product/abc123
I have tried a couple of variations on this and just cannot get this to pick it up (despite testing this in the IIS URL rewrite regex tester).
<rule name="Custom rule 12" stopProcessing="true">
<match url="aaa/bbb/product/(.*)" />
<conditions>
<add input="{HTTP_URL}" pattern="~productId=(.*)$" />
</conditions>
<action type="Redirect" url="/product/{C:1}" appendQueryString="false" />
</rule>
According to your description, I suggest you could try to use below url rewrite rule.
<rule name="specialcharacter" stopProcessing="true">
<match url="aaa/bbb/product/~productId=(.*)" />
<action type="Redirect" url="https://www.example.com/product/{R:1}" />
</rule>
Result:
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" />
Is it possible to redirect using web.config based on the presence of a querystring in the initially requested URL? I'm not sure what to include in the the conditions. I'm a beginner at working with rewrite/redirect rules in web.config and would like to learn more about syntax, parameters etc.
I'm trying to do something like this:
<rewrite>
<rules>
<rule name="Restricted Folder with Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />
<conditions>
<!--redirect to a certain page if a certain querystring is present -->
</conditions>
<action type="Redirect" redirectType="Permanent" url="/test folder/{R:1}" />
</rule>
<rule name="Restricted Folder without Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />
<conditions>
<!--redirect to another page if querystring is not present -->
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://www.whatever.com/page.asp?url={R:1}" />
</rule>
</rules>
</rewrite>
deeholzman, I believe for your Condition - Add Input example you want to use "pattern" and not "matchType". EX:
<add input="{QUERY_STRING}" pattern="^whateverpattern" />
or
<add input="{QUERY_STRING}" pattern="^whateverpattern" negate="true" />
I found the answer in the URL Rewrite Module Configuration Reference. In the rewrite section of web.config in whatever folder you wanted to perform the redirect from, it would go something like this:
<rules>
<rule name="Restricted Folder Gimbal" stopProcessing="false">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="^whateverpattern" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://www.whatever.com/file.html" />
</rule>
</rules>
For a querystring not present, you could add the 'negate' parameter to the condition:
<add input="{QUERY_STRING}" pattern="^whateverpattern" negate="true" />
The the URL Rewrite Module Configuration Reference is a very handy reference that unfortunately took me longer than expected to find.