Forum Moderators: phranque

Message Too Old, No Replies

redirect non-www to www with .htaccess

questions from a non-techie webmaster

         

fearlessrick

2:00 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Some of us in the Google news forum have been bouncing this around and somebody suggested I ask here. I think I have the code right, but now my question is: what directory is my root. I know, I should know that, but read on.

I have the following structure in my ftp setup: / -- home -- mysitename -- www -- subdirectories.

OK, now I'm really confused. I am on a shared server. In directory / are all kinds of files I don't mess with like bash_history, bin, boot, etc. In directory "home" are everybody's sitenamed folders, including mine. In mysitename directory are more files I don't mess with, bash_history, .pinerc, .redirect (I have to look at that one), etc. plus my www folder. I now have .htaccess file in both the mysitename and www directories. Somebody please help me out here?

I am assuming that the www is what most of you are calling "root". Please correct me if I'm wrong.

Below is the code I'm using on a Unix server, which I believe is Apache.

-------------

Options +FollowSymLinks
AllowOverride FileInfo
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) [example.com...] [R=301,L]

------------

jd01

4:45 pm on Jun 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi stu2,

The code you posted should work for internal directories also, as long as the code is in the 'root' (main) directory .htaccess.

Have you tested the version posted? (I'm guessing you have, but it doesn't hurt to ask.)

Are you sure your browsers cache was emptied when you tested? (I've forgotten this on a large number of occasions.)

Are you using any .htaccess files in specific directories that are not redirecting? (If this is the case, try adding the lines of code you posted to the top of the .htaccess file in the specific directory.)

Justin

stu2

1:38 am on Jun 29, 2005 (gmt 0)

10+ Year Member



"The code you posted should work for internal directories also, as long as the code is in the 'root' (main) directory .htaccess."

Yep it's in the root directory.

"Have you tested the version posted? (I'm guessing you have, but it doesn't hurt to ask.)"

Well, blush, I actually hadn't. I'd read somewhere on one of these forums someone stating that they'd done this 301 redirect from domain.com to www.domain.com and they'd stated they done this for their sub-dirs as well. So I'd assumed there was another command to put in my .htaccess file (but presumably they meant they'd put something similar in the sub-dirs .htaccess file).
I just tested it, and the sub-dirs seem to be resolving to www.domain.com. So all seems to be well.

"Are you sure your browsers cache was emptied when you tested? (I've forgotten this on a large number of occasions.)"

Me too :( I usually remember when I double/triple checked my syntax etc, make sure I've uploaded the .htaccess file at least 3 times, scratching my head... this *should* be working.. then... click... lightbulb goes on... clear cache... everything working :)

"Are you using any .htaccess files in specific directories that are not redirecting? (If this is the case, try adding the lines of code you posted to the top of the .htaccess file in the specific directory.)"

Nope. Just in the root directory. Thanks for your help.

trillianjedi

10:18 am on Jul 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm now having some problems with this.

Have tried it two ways (have never ever managed to get this working):-


RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mydomain\.org [NC]
RewriteRule (.*) http://www.mydomain.org/$1 [R=301,L]

and


RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.org
RewriteRule ^(.*) http://www.mydomain.org/$1 [L,R=301]

I have also tried pretty much all of the examples in the rest of this thread.

Is there a possibility that we have a configuration problem somewhere?

Thanks,

TJ

[edited by: jdMorgan at 7:57 pm (utc) on July 11, 2005]
[edit reason] Unlinked. [/edit]

jdMorgan

7:57 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you geting anything in your server error log while testing these? Either version of the code should work fine.

You may need to enable mod_rewrite by adding


Options +FollowSymLinks

or

Options +SymLinksIfOwnerMatch

ahead of RewriteEngine on.

Or you may indeed have a server config problem; The error log will usually tell you what's wrong.

Jim

trillianjedi

9:55 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks JD - actually I moved here:-

[webmasterworld.com...]

...as this thread seemed to die on me ;-)

Thanks,

TJ

scents1

4:37 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Does anyone know if there's a way to 301 re-direct from my www. to my non-www. with a Yahoo! Legacy Store? Yahoo! does not allow ftp access to the server. 90+ percent of my links point to my non-www. but G seems to be splitting the PR between the two homepages (both PR4 with internal PR4's). The non-www. has been as high as PR7 in the past. My domain is registered at GoDaddy.

Chuck

This 36 message thread spans 2 pages: 36