Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Mar 16, 2009 5:28 am 
Offline
Junior Member

Joined: Wed Mar 04, 2009 11:10 pm
Posts: 29
I've been trying to redirect www.domain.com to domain.com for 4 hours and I'm getting no where. I have no idea how to do this and I've tried following tutorials but nothing is working. I sign into my site on domain.com, but when I go to www.domain.com I'm at my site but the session is different because I'm not logged in at www.domain.com, only at domain.com. How can I do the redirect?


Top
   
 Post subject: re redirect
PostPosted: Mon Mar 16, 2009 8:13 am 
Offline
Junior Member

Joined: Thu Nov 08, 2007 12:40 am
Posts: 34
I am not sure what you are trying to do. Do you have a cname in your nameserver for www.domain.com? If you do that apache should handle either request.

fb


Top
   
 Post subject:
PostPosted: Mon Mar 16, 2009 8:56 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 23, 2008 10:10 am
Posts: 71
Website: http://frontseed.com/
mod_rewrite module needs to be enabled for this to work.

You can set up a rewrite in your virtual host configuration, or in a .htaccess file placed in your website root directory (make sure AllowOverride is set to All to use rewrite directives in .htaccess)

Code:
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
  RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
</IfModule>


Top
   
 Post subject:
PostPosted: Mon Mar 16, 2009 9:12 am 
Offline
Senior Member

Joined: Sun Aug 31, 2008 4:29 pm
Posts: 177
Sounds like you need to use Apache rewrite to rewrite requests for http://domain.com to http://www.domain.com

There are various ways of formulating the rewrite rules. Try googling for "apache rewrite force www" or something like that that. You'll find lots of examples that vary slightly.

A basic example is on this Apache 1.3 docs page... http://httpd.apache.org/docs/1.3/misc/rewriteguide.html (scroll down a little to "Canonical Hostnames").


Top
   
 Post subject:
PostPosted: Mon Mar 16, 2009 8:16 pm 
Offline
Junior Member

Joined: Wed Mar 04, 2009 11:10 pm
Posts: 29
Which would be better? A rewrite or a redirect? I got it working with a redirect finally, but it seems to me a redirect would be faster and take up less resources since Rewriting has parsing, right?


Top
   
 Post subject:
PostPosted: Mon Mar 16, 2009 10:00 pm 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
Just do this

Code:
 ServerName example.net
 ServerAlias www.example.net


Top
   
 Post subject:
PostPosted: Tue Mar 17, 2009 12:12 am 
Offline
Senior Member

Joined: Tue Apr 29, 2008 6:26 pm
Posts: 58
Website: http://blog.shadypixel.com/
sneaks wrote:
Which would be better? A rewrite or a redirect? I got it working with a redirect finally, but it seems to me a redirect would be faster and take up less resources since Rewriting has parsing, right?


Ultimately, you want to do a 301 redirect.

To accomplish that, you can use apache's mod_rewrite (see melon's post) or you can use mod_alias and the redirect command. It's really up to you. A lot of people end up using mod_rewrite because they're using it for other things already and it's a bit more flexible than mod_alias.


Top
   
 Post subject:
PostPosted: Tue Mar 17, 2009 10:55 am 
Offline
Junior Member

Joined: Mon Mar 16, 2009 3:38 pm
Posts: 30
Website: http://vitobotta.com
Location: Espoo, Finland
kangaby wrote:
Just do this

Code:
 ServerName example.net
 ServerAlias www.example.net


was just wondering why all were suggesting redirecting or rewriting instead, and about to post this before seeing your comment :D


Top
   
 Post subject:
PostPosted: Tue Mar 17, 2009 12:50 pm 
Offline
Senior Member
User avatar

Joined: Sun Feb 08, 2004 7:18 pm
Posts: 562
Location: Austin
Vito Botta wrote:
was just wondering why all were suggesting redirecting or rewriting instead, and about to post this before seeing your comment


Because the original poster specifically asked for how to do redirection.

He's already got this up and running, his problem was that he wanted people trying to go to "domain.com" to end up at "www.domain.com", not just seeing the same stuff, but with that address in the URL bar.


Top
   
 Post subject:
PostPosted: Tue Mar 17, 2009 2:09 pm 
Offline
Junior Member

Joined: Mon Mar 16, 2009 3:38 pm
Posts: 30
Website: http://vitobotta.com
Location: Espoo, Finland
Xan wrote:
Vito Botta wrote:
was just wondering why all were suggesting redirecting or rewriting instead, and about to post this before seeing your comment


Because the original poster specifically asked for how to do redirection.

He's already got this up and running, his problem was that he wanted people trying to go to "domain.com" to end up at "www.domain.com", not just seeing the same stuff, but with that address in the URL bar.


Oops, you're right - he was indeed talking about redirection :)


Top
   
 Post subject:
PostPosted: Thu Mar 19, 2009 10:01 pm 
Offline
Senior Member

Joined: Wed Oct 20, 2004 8:55 am
Posts: 120
Xan wrote:
he wanted people trying to go to "domain.com" to end up at "www.domain.com", not just seeing the same stuff, but with that address in the URL bar.


I guess I don't really understand the point. If www.domain.com is the same content as domain.com, then why do a redirection at all.
If you really want them to only use www.domain.com then set the server name to www.domain.com and don't alias domain.com
Then only www.domain.com will work.
Is there some special secret setup I'm missing here?


Top
   
 Post subject:
PostPosted: Thu Mar 19, 2009 10:33 pm 
Offline
Senior Member

Joined: Tue Apr 29, 2008 6:26 pm
Posts: 58
Website: http://blog.shadypixel.com/
kangaby wrote:
Xan wrote:
he wanted people trying to go to "domain.com" to end up at "www.domain.com", not just seeing the same stuff, but with that address in the URL bar.


I guess I don't really understand the point. If www.domain.com is the same content as domain.com, then why do a redirection at all.
If you really want them to only use www.domain.com then set the server name to www.domain.com and don't alias domain.com
Then only www.domain.com will work.
Is there some special secret setup I'm missing here?


Users expect websites to be available at both example.com and www.example.com. Making only one or the other work is just going to confuse and frustrate your visitors (or worse, make them think the site is down).

So, the only question is: do you serve the same content from both example.com and www.example.com or do you redirect one to the other?

Redirecting one to the other is usually the better solution. Users will always be presented with your "preferred" url. Also, if people link to your site using both example.com and www.example.com, using a 301 redirect tells google that all that pagerank flow should be consolidated into one page. If you're serving content from both, then google is going to have two pages in its index and they're both probably not going to perform very well in search results because the links are split between them.


Top
   
 Post subject:
PostPosted: Fri Mar 20, 2009 7:34 am 
Offline
Senior Member

Joined: Sun Aug 31, 2008 4:29 pm
Posts: 177
btmorex wrote:
Redirecting one to the other is usually the better solution. Users will always be presented with your "preferred" url. Also, if people link to your site using both example.com and www.example.com, using a 301 redirect tells google that all that pagerank flow should be consolidated into one page. If you're serving content from both, then google is going to have two pages in its index and they're both probably not going to perform very well in search results because the links are split between them.


It also resolves confusion with cookies and sessions. You might be logged in to www.example.com and then visit example.com where you aren't logged in. Which is the original issue....


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group