Selasa, 03 Juli 2007

Apache redirect domain.com to www.domain.com

Q. What’s the best way to redirect domain.com to www.domain.com on the url address bar whenever someone omits or skip the www from domain.com? My site can be reached by two different URLs. For example http://domain.com/about/us.html and http://www.domain.com/about/us.html

How do I do configure Apache web sever vps for this task?

A. Apache (web server) 301 redirect is the most efficient and search engine friendly method for webpage redirection. You can place following code Apache’s httpd.conf vhost section or in .htaccess file.

$ vi .htaccess
Append following config code:

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

Save and close the file. Above code will redirect users to www.domain.com url.

If you get stuck on something or have a question please discuss this faq/howto in the nixCraft forum. You can subscribe to our free e-mail newsletter or RSS feed or Leave a reply/comment.

You may also be interested in (skip to comment)...



Tidak ada komentar: