Tag Archives: apache

Configuring redirections with apache htaccess for www, non-www, http and https | All patterns

There could be 10 different reasons to have a specific pattern of domain name considering brand value, technical architecture, personal liking, search engine optimizations, etc. And you might encounter a requirement of http redirections where you may need to do add/edit the htaccess of your webserver.

 Understand, this blog is just to help you achieve the results and not about explaining each bit of code. 

Prerequisites

  • This tutorial assumes that you have enough technical knowledge about setting up a website on apache.
  • If you are using Linux make sure you have superuser privileges, i.e. sudo or root, on the server that is running Apache.
  • It is assumed that you have Apache installed.
  • You must be able to add records to the DNS that is managing your domain. If you do not already have a domain, you may purchase one from a domain registrar, and manage it with the registrar’s DNS.
  • Enable Rewrite Module: In order to perform the 301 redirect, we will use the Apache mod_rewrite, or Rewrite, module. Doing so will ensure that your users can access your site with or without the www. prefix, and be redirected to the domain that you prefer.
  • Created an .htaccess file on the web server root folder for http redirections.

Apache htaccess configurations for http redirections from www to non-www and vice-versa with https options on/off.

If you are reading this post, it means you are technical enough to understand about this topic. So let me quickly jump to specific solutions to different requirements:

Condition 1: To get www without https

Example:

  1. http://example.com ⇨ http://www.example.com
  2. https://example.com ⇨ http://www.example.com
  3. https://www.example.com http://www.example.com

Result: http://www.example.com

Continue reading Configuring redirections with apache htaccess for www, non-www, http and https | All patterns