File web.config re-write rules guide

In this guide you’ll find useful codes of redirecting & re-writing rules in web.config file, and here are available codes:

  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 redirect to new domain name
  5. Redirect specific page to another specific page
  6. Redirect non WWW to WWW
  7. Force add WWW to domain name
  8. Force remove WWW from domain name

*  When you copy one of these codes to your web.config file make sure to past it inside re-write section { <rewrite>  [pasted 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 🙂

Leave a Reply

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