IIS rewrite with unusual ~ character in the URL - redirect

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:

Related

After write the rule, every page is redirected to the error page

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>

IIS rewrite rule not passing parameters

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.

How do I redirect www.mypage.com/this/that to www.mypage.com in IIS

<rule name="url rewrite"
stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect"
url="" />
</rule>
What do i put in the in the action url to just have it redirect to the current domain.
trying to turn www.mypage.com/this/that/whatever.aspx to this www.mypage.com
If you want to redirect to homepage, you can just use /. It will looks like that
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="/" />
</rule>
For ex. if you want to redirect to www.mypage.com/abc, you can use like that:
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="/abc" />
</rule>
In case if you want to redirect to another domain www.otherdomain.com, you should use it like that:
<rule name="url rewrite" stopProcessing="true">
<match url="This/That/Something(.*)$" />
<action type="Redirect" url="http://www.otherdomain.com" />
</rule>

iis url redirect http to non www https

i need to redirect from
www.domain.de to https://domain.de
-works
http://www.domain.de to https://domain.de
-works
http://domain.de to https://domain.de
-does not work
rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I think this will work for you, the search pattern has the optional www and redirects using the back reference C:2, the rule has a condition to only run against non https.
This is the pattern:
"^(www\.)?(.*)$"
where:
{C:0} - www.domain.de
{C:1} - www.
{C:2} - domain.de
Here's the rule in full:
<rewrite>
<rules>
<rule name="SecureRedirect" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
The accepted answer doesn't handle the special case https://www.domain.de.
These rules do the complete job:
<rewrite>
<rules>
<rule name="Redirect to HTTPS without www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Special case for HTTPS with www" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^ON$" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
If you want to redirect www to non www:
Add DNS entry for www.yourdomain.com to refer to your server's public IP
Then you need to Edit Bindings of your website and "Add Binding" www.yourdomain.com
Add a rewrite rule to your website using iis:
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>
Reference: http://madskristensen.net/post/url-rewrite-and-the-www-subdomain
If you want something more flexible than for your three examples, change your HTTP_HOST pattern to : \w+\.\w+$. That would work for all three examples plus anything else, like subdomain.abcdef.domain.de.
If you use this regex either encase it in parenthesis or change C:1 to C:0 in your action.
This is what worked for me:
<rule name="NameRule1" stopProcessing="true" enabled="true" >
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://example.com/{R:1}" />
</rule>
I got it from: https://medium.com/iis-and-windows-server/redirect-url-from-www-to-non-www-in-iis7-5-4d2909b9704
Redirecting https://www.example.com to https://example.com I had to do 2 steps
Select the website, click "URL Rewrite" -> Click "Add Rule" -> Choose "Cononcial domain name" -> select your domain (without the www) -> make sure rule is at the top -> highlight the rule and click "Edit" -> and update "Redirect URL" at the end of the rule to include the 's' - https://example.com/{R:1}
I had to also create a new website with the domain www.example.com, new app pool and select the SSL cert and point it to a folder containing the following (for some reason StackOverflow wont display the code I pasted below for the rewrite rule but just google IIS rewrite rule)
After doing both steps only then does it work as desired
Tried many of solutions but below works for me:
Right click on Domain and Add a Site bindings, add one more domain with www:
2. Restart services. it should work.
These rewrite rules matches the following URL's:
www.example.com
http://www.example.com
https://www.example.com
They will all redirect to: https://example.com
These rewrite rules may redirect twice because of the separate rules. (I'm a newbie with regex)
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<rule name="WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="https://example.com{PATH_INFO}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Redirect Loop - IIS7

Getting a redirect loop when using the below rule on IIS7 using the rewrite module.
<rule name="redirect" stopProcessing="true">
<match url="test" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/new/test" appendQueryString="false" redirectType="Permanent" />
</rule>
Any ideas?
Thanks
Looks like you are trying to redirect from http://domain.com to http://www.domain.com
Believe the correct pattern should be "^domain\.com$"
This matches the entire HTTP_HOST value of "domain.com"