Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

.htaccess domain.com to www.domain.com redirect

Views: 60
Votes: 0

Google and most search engines see domain.com and www.domain.com as two different sites/pages. The problem is if you get links to your site, some with the www and some without, your total number of links isn't the true total. It's split between the two. Using .htaccess and mod_rewrite, you can do a 301 redirect to the www version.

Below is some code that will help:

rewriteEngine on
RewriteCond % ^domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
The first line turns the rewrite thing on, if it was off.

The second line checks for the host. The ^ means the beginning and the $ means the end.

The third line, no checking what comes after the host, will forward any directories/files from domain.com to your domain with the www. The $1 is the variable that hold the directories/files, so yourdomain.com/some/directory/file.html would have $1 equal to some/directory/file.html. The R=301 forces a 301 permanent move redirect. Google will then see it as one domain. The L says it's the last rule. If you add other rules and leave off the L, it would go through them all before finally redirecting.

Please let us know if you have any further questions by submitting a support ticket.

Others in this Category
document What are some basic software paths?
document How do I change File Permissions?
document What is SSI (Server side includes) and how can I use it?
document Where do I place CGI scripts?
document What is the path to sendmail?
document What is the path to my home directory?
document What are valid file extensions I can use for PHP scripts?
document What is PHP and how do I use it?
document How do I provide streaming - Audio / Video ?
document How do I edit the text of my web page?
document Can I run PHP scripts anywhere on my site?
document What are some basic SSI tags/features?
document What is the path to perl?
document Which php modules are installed on servers?
document How do I make SSI (Server Side Includes) work in .html?
document Backing up MYSQL Via Cron
document Header Redirect
document Where can I download free PHP scripts?
document 500 Internal Error
document What do the different HTTP Status Codes like 200, 304, 404, 401, 403 mean?



RSS