Redirect & re-write rules with web.config

Redirect & re-write rules with web.config

Step-by-step tutorial. How to set web.config rules [Redirect & re-write]

  1. Redirect HTTPS to HTTP
  2. Redirect HTTP to HTTPS
  3. Redirect old domain name to new domain name
  4. Redirect old domain name to new domain name and keep the rest of URL the same when redirecting to the new domain name
  5. Redirect specific page to another specific page
  6. Redirect non-WWW to WWW
  7. Force add WWW to the domain name
  8. Force remove WWW from domain name

*  When you copy one the codes below to your web.config file make sure to past it inside re-write element { <rewrite>  [copied code]  </rewrite> }


1.Redirect HTTPS to HTTP

  • Domain name = https://mydomain.com/

*  This will redirect https to http

Example:

  1.  https://mydomain.com/  >>> http://mydomain.com/
  2.  https://mydomain.com/somepage/ >>> http://mydomain.com/

2.Redirect HTTP to HTTPS

  • Domain name = http://mydomain.com/

*  This will redirect http to https

Example:

  1.  http://mydomain.com/  >>> https://mydomain.com/
  2.  http://mydomain.com/somepage/ >>> https://mydomain.com/

3.Redirect old domain to new domain

  • Old domain = http://olddomain.com/
  • New domain = http://newdomain.com/

*  This will redirect your old domain name to your new domain name when user type the old domain name in browser.

Example:

  1.  http://olddomain.com/  >>>  http://newdomain.com/
  2.  http://olddomain.com /somepage/ >>>  http://newdomain.com/

4.Redirect old domain to new domain and keep the rest of URL when redirect to new domain

  • Old domain = http://olddomain.com/
  • New domain = http://newdomain.com/

*  This will redirect your old domain name to your new domain name when user type the old domain name in browser and it will keep the rest of URL from the old domain name and post it to the new redirected domain name.

Example:

  1.  http://olddomain.com/  >>>  https://newdomain.com/
  2.  http://olddomain.com /somepage/ >>>   https://newdomain.com/somepage/

5.Redirect specific page to another specific page

  • Page one = http://mydomain.com/pageone
  • Page two = http://mydomain.com/pagetwo

*  This will redirect [pageone] to [pagetwo] when user try to access page one

Example:

  1.  http://mydomain.com/pageone  >>>  http://mydomain.com/pagetwo
  2.  http://www.mydomain.com/pageone  >>>  http://mydomain.com/pagetwo

6.Redirect non WWW to WWW

  • Domain name = http://mydomain.com/

*  This will redirect non WWW domain name to WWW one

Example:

  1.  http://mydomain.com/  >>>  http://www.mydomain.com/
  2.  http://www.mydomain.com/  >>>  http://www.mydomain.com/

7.Force add WWW to domain name

  • Domain name = http://mydomain.com/

*  This will force add WWW to your domain name when user type it like this: http://mydomain.com/

Example:

  1.  http://mydomain.com/  >>>  http://www.mydomain.com/
  2.  http://www.mydomain.com/  >>>  http://www.mydomain.com/

8.Force remove WWW from domain name

  • Domain name = http://www.mydomain.com/

*  This will force remove WWW from your domain name when user type it like this: http://www.mydomain.com/

Example:

  1.  http://www.mydomain.com/  >>>  http://mydomain.com/
  2.  http://mydomain.com/  >>>  http://mydomain.com/

Good luck 🙂

6 thoughts on “Redirect & re-write rules with web.config”

  1. Helpful information. Lucky me I found your web site unintentionally,
    and I’m stunned why this coincidence did not happened in advance!
    I bookmarked it.

Leave a Reply to Daryl Ballmann Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.