Trick to redirect website root page

I needed to do two things –

  1. redirect all access to my website without www prefix(example to url with prefix www (
  2. redirect root page of the website to a page under some subdirectory. That is should redirect to

Website is hosted on bluehost. I later learnt the website is using apache server. It is simple stuff for someone who is hosting or building websites for long. I need to search and try couple of tricks on the cpanel before I could get it to work.

Here is how it works:

  1. There is .htaccess file in the public_html (root folder). File is hidden and file manager cpanel needs to be launched with checkbox (hidden) ticked.
  2. Edit this file.
  3. This file is processed by apache web server, and url rewrite rules can be written in this file.
  4. script snippet below saved in the .htaccess file, worked for me to achieve this.
  5. you can refer the documentation of redirects here.
RewriteEngine on

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R=301]

RewriteCond %{HTTP_HOST} ^$
RewriteRule ^$ [L,R=301]
This entry was posted in Hosting Website and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s