OCS Solutions Web Hosting Design and Consulting Web Hosting and Consulting Call Us
OCS Home  |  Wiki Front Page  |  Web Hosting  |  Virtual Dedicated Servers  |  Consulting  |  Support  |  Contact Us

Redirect Non WWW

From OCS Support Wiki

Jump to: navigation, search

Introduction

For search engine purposes, you may want to redirect all requests without the www in the domain portion of the URL to www.yourdomain.com. If someone goes to yourdomain.com, this guide will show you how to transparently redirect them to www.yourdomain.com.

Setting Up the Redirect

To enable this redirect, create an .htaccess file in cPanel's File Manager, your FTP client, or via SSH in the public_html folder of your account. You may have to enable an option in your FTP client called "show hidden files" or similar to see an .htaccess file after you create it. Via SSH, ls will not show an .htaccess file, but ls -la will.

The file should contain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

In the above example, replace yourdomain.com with your real domain name.

If you have other items in your .htaccess file already, add this to the top. Only one RewriteEngine On directive is needed, so if you already have that in your file, you can remove that.

Personal tools