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

<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>

Related

IIS Redirect Rule to redirect one url to another

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>

IIS rewrite with unusual ~ character in the URL

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:

IIS two domains one website with query redirect

I have problem with redirection on my IIS. I have two domains in Bindings to one website, and I have redirect example1.com to example.com but I want to redirect query too
What i Have:
main domain: example.com
example1.com => example.com - this work
But what I want:
example1.com/test => example.com/test - this not working
What I'm trying:
<rule name="Rewrite domain requests" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^.*example1.com/([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Rewrite" url="example.com/={R:1}" appendQueryString="true" />
</rule>
Second try:
<rewrite>
<rewriteMaps>
<rewriteMap name="https://example.com/" />
</rewriteMaps>
<rules>
<rule name="Przekierowanie" stopProcessing="true">
<match url="(.*)example1.com/(.*)/" ignoreCase="false" />
<action type="Redirect" url="http://example.com/{R:2}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
How i can do this?

redirect non-www to www for an internal page's url

I want to redirect:
domain.co.uk to www.domain.co.uk and
domain.co.uk/contact-us to www.domain.co.uk/contact-us.
I have tried dozen of web.config rules with ECMAScript and Wildcard but first one is done but second one either remain same or redirect to www.domain.co.uk i.e. home page. A example of what is there at the moment is as below:
<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.co.uk/*" />
</conditions>
<action type="Redirect" url="http://www.domain.co.uk/{C:1}/{R:0}" />
</rule>
This will redirect to the www version while preserving the HTTP and HTTPS protocol:
<rule name="ensurewww" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
</conditions>
<action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>

How to redirect all traffic to https & non-www in web.config?

I'm using an SSL certificate and IIS. In my web.config I want to redirect all website traffic in the following order:
all http --> https
all www --> non-www
You want to use the redirect module in order to do this. This intercepts the request as it's coming in to the server and changes it according to your instructions.
Here is an action to redirect all to https:
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
and here is one to redirect www to non-www:
<conditions> <add input=”{HTTP_HOST}” pattern=”^example\.com$” negate=”true” /> </conditions> <action type=”Redirect” url=”http://example.com/{R:1}” />
There are plenty of articles around the web and StackOverflow when you include both "web.config" and "redirect" in your search.
Make sure that when you set up the rules you only use stopProcessing="true" on the final rule. If that appears on the first rule then the second rule will never execute.
i find the answer
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="NonWwwRedirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.yoursit\.com$" />
</conditions>
<action type="Redirect" url="http://yoursite.com/{R:1}" />
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
<system.webServer />