Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Appending www to url
PostPosted: Sat Sep 01, 2012 8:05 am 
Offline
Senior Member

Joined: Tue Aug 14, 2012 5:55 pm
Posts: 82
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.net/$1 [R=301,L]

the above code works for http://www.example.net but only http://example.net is giving "page not found"

I simply want www appended automatically. Please help.


Top
   
 Post subject: Re: Appending www to url
PostPosted: Sat Sep 01, 2012 8:18 am 
Offline
Linode Staff

Joined: Fri Feb 18, 2011 10:08 am
Posts: 42
Location: Galloway, NJ
Try this:

RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]


Top
   
 Post subject: Re: Appending www to url
PostPosted: Sat Sep 01, 2012 3:50 pm 
Offline
Senior Member

Joined: Tue Aug 14, 2012 5:55 pm
Posts: 82
didn't work ! :(


Top
   
 Post subject: Re: Appending www to url
PostPosted: Sun Sep 02, 2012 8:27 am 
Offline
Senior Member

Joined: Tue Aug 14, 2012 5:55 pm
Posts: 82
It seems the problem still persists, my browser cache has been fooling me.


It turned out to be more of a redirection problem than rewrite rules so here is the solution.

In linode dns
example.com

In Virtual host
servername http://www.example.com
serveralias example.com

In the website directory .htaccess file is supposed to contain;

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


Last edited by sami1255 on Sun Sep 02, 2012 3:45 pm, edited 1 time in total.

Top
   
 Post subject: Re: Appending www to url
PostPosted: Sun Sep 02, 2012 12:13 pm 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
Is the goal to make http://www.example.net/ == http://example.net/ ?

If so then you don't need a redirect rule just make sure your DNS is setup right.


Top
   
 Post subject: Re: Appending www to url
PostPosted: Sun Sep 02, 2012 12:44 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
The goal, most likely, is to have exactly one of 'www.example.com' or 'example.com' be the canonical hostname for the site by redirecting the "wrong" one to the "correct" one. This is generally considered a good thing to do, both for aesthetics and for making things easier on web crawlers. (It's real SEO, in other words.)

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
 Post subject: Re: Appending www to url
PostPosted: Sun Sep 02, 2012 3:53 pm 
Offline
Senior Member

Joined: Tue Aug 14, 2012 5:55 pm
Posts: 82
@jebblue,

yes the idea is to have a website which is accessible by http://www.example.net to be reached via example.net. @hoopycat is right. we want to achieve it for better seo.

http://www.example.net (currently the link is working fine)
&
example.net (currently the link gives page cannot be displayed)

to reach

http://www.example.net


Can't make it more clearer than this :(


Top
   
 Post subject: Re: Appending www to url
PostPosted: Mon Sep 03, 2012 1:30 am 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
Check if you can you ping both www and just the domain name and get back a response. Check if nslookup or dig see both names.


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


Who is online

Users browsing this forum: No registered users and 4 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