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)...
- Apache prevent hot linking or leeching of images using mod_rewrite howto
- How do I find out syntax errors in my Apache web server configuration file?
- Forbidden - You don’t have permission to access this page error and solution
- How to install and start the Apache or httpd service under Linux
- My scripts in cgi-bin directory not working, how do I troubleshoot this problem?


Tidak ada komentar:
Posting Komentar