Hi, I am very much aware of the benefits of redirecting non-www url's to www url's. Now, meta refresh is something that doesn't considered to be a good practice as far as permanent redirect is concerned. Another alternative is .htaccess file. At the moment I thoroughly unaware of what are the contents of a .htaccess file. Guys please let me know how should I create .htaccess file from scratch ? Looking for positive replies. Thanks in Advance
The file is called .htaccess (dot on the front) and it goes in the html root directory. Use the following 3 lines: RewriteEngine on RewriteCond %{HTTP_HOST} ^yourhost.com [NC] RewriteRule ^(.*)$ http://www.yourhost.com/$1 [L,R=301] Changing yourhost.com to your domain name
Matt check out the following code - This is the exact code I put in the .htaccess file..that's my websit - http://mosymadugba(dot)com RewriteEngine on RewriteCond %{HTTP_HOST} ^mosymadugba.com [NC] RewriteRule ^(.*)$ http://www.mosymadugba.com/$1 [L,R=301] still the non www url is not rediecting towards www url's
This is wrong, and thats why it doesnt work. Test it here for example: http://havocarcade.com try this at the top of .htaccess note- create/place the .htaccess file in your public_html directory like so: /public_html/.htaccess/
replace RewriteCond %{HTTP_HOST} ^mosymadugba.com [NC] to RewriteCond %{HTTP_HOST} ^mosymadugba.com it should be working now
[NC] means "Case Insensitive", and this is how you set it up in .htaccess ( i am using it on my site myself) 301 tells the browsers and search engines that this is a permanent redirect L means last rule ^ Start of line anchor For those of you who need more info on URL rewrites see: http://www.widexl.com/tutorials/mod_rewrite.html This is what he needs to add to .htaccess in /public_html/.htaccess
I believe [NC] was used in older versions of apache I tried both versions in my htaccess ( iam using apache2) and it works only without [NC]