IT.COM

Redirecting sitename to www.sitename

Spaceship Spaceship
Watch

Keral_Patel

I'll do itRestricted (Chatroom)
Impact
1,435
Redirecting your sitename.com to www.sitename.com with help of .htaccess

Create a .htaccess file or add the code to an existing one on your server.

If you are creating a new .htaccess file make sure it is in the root folder of the site.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^sitename.com [nc]
rewriterule ^(.*)$ http://www.sitename.com/$1 [r=301,nc]

Where sitename.com and www.sitename.com will be replaced by your original details of the site itself.

This will only work on apache servers with mod_rewrite enabled.
 
Last edited:
3
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
And last but not least - do not forget about last empty line (just hit Enter after last line of code twice) :)
 
0
•••
The alternative rule:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.site\.us$ [NC]
RewriteRule ^(.*)$ http://site.us/$1 [R=301,L]
 
Last edited:
0
•••
Thanks worked like a charm!
 
0
•••
Thanks, Nick. I've been too lazy to dig up this code. ;)
 
0
•••
So does it mean if I type sitename in brouther it redirects you to sitemname.com? I have seen such situations, but I thought it is google.
 
0
•••
Waiter said:
So does it mean if I type sitename in brouther it redirects you to sitemname.com? I have seen such situations, but I thought it is google.


It means if you type in sitename.com it
takes you to www.sitename.com

:)
 
0
•••
By the way,
I heard, that Google like website which are redicting from http:// to http://www.
I mean, it help with PageRank.
 
0
•••
Pointer said:
By the way,
I heard, that Google like website which are redicting from http:// to http://www.
I mean, it help with PageRank.

Never heard of that.
Never had proof of that.

Could you tell me where you found this information?
 
0
•••
0
•••
0
•••
are there any other ways of doing this as its not working for my site

www.7dl.com resolves, 7dl.com doesnt
 
0
•••
I have default .htaccess :
Code:
# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.{mydomain}.com
AuthUserFile /home/iwantw/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/iwantw/public_html/_vti_pvt/service.grp

Where should i add the add-on htaccess code?
 
0
•••
am i know why i must directing ?
and because as i can see there some people just prefer to http://domain and some people have choose http://www.domain so, which one the best ?
and if i want to use http://domain is it right the code off httacsess
Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^\.site\.us$ [NC]
RewriteRule ^(.*)$ http://site.us/$1 [R=301,L]

regards
 
0
•••
xrvel said:
I have default .htaccess :
Code:
# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.{mydomain}.com
AuthUserFile /home/iwantw/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/iwantw/public_html/_vti_pvt/service.grp

Where should i add the add-on htaccess code?

Add the code umat_gila pasted above,
on a new line in your .htaccess right after what you posted above.
 
0
•••
mis_chiff said:
Add the code umat_gila pasted above,
on a new line in your .htaccess right after what you posted above.
Thanks. it works :D
 
0
•••
xrvel said:
I have default .htaccess :
Code:
# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.{mydomain}.com
AuthUserFile /home/iwantw/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/iwantw/public_html/_vti_pvt/service.grp

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^\.site\.us$ [NC]
RewriteRule ^(.*)$ http://site.us/$1 [R=301,L]

thats the conclusion right ?
ill try
 
0
•••
-Nick- said:
Redirecting your sitename.com to www.sitename.com with help of .htaccess

Create a .htaccess file or add the code to an existing one on your server.

If you are creating a new .htaccess file make sure it is in the root folder of the site.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^sitename.com [nc]
rewriterule ^(.*)$ http://www.sitename.com/$1 [r=301,nc]

Where sitename.com and www.sitename.com will be replaced by your original details of the site itself.

This will only work on apache servers with mod_rewrite enabled.

Tested on my site and working wery well , rep+
Thanks
 
0
•••
Thanks :) I am much happy that it helped you all. It is this that always inspires me to write stuff :p
 
0
•••
The reason why you might do this for google or any other search engine is that there is a limit as to how many characters the crawler recognizes in the url. So if you have a long url with a lot of keywords in it the loss of the www gives you three extra characters.

I think limit is like 255 characters typically which is a lot, but if you have some script generating your page names it could happen.
 
0
•••
That's a good suggestion trampy :)

Will keep it in mind whenever there is a situation like this. But it rarely comes. Yet it might be beneficial for someone :)

Thanks for posting it :)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back