htaccess Redirects

I’m looking at adjusting a htaccess file to redirect anyone from example.com to www.example.com to avoid duplicate clutter in the search engines. However I was wondering how one would do that to include any site that exists within a subfolder or does it have to? Meaning how would I redirect someone from example.com/site2 to www.example.com/site2 and would I just set the htaccess file in the root or would I have to create two separate htaccess files (one in the root and one in the subfolder).

So far I found this for the first part, but how would it look for a subfolder:

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

I’m not a pro at these kinds of files, but any help would be great.


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That looks like it will work, and no, one will do nicely, as long as
you place the .htaccess file at the outermost public site root folder
on the server. The $1 part of the redirect rule will capture and
translate anything after the hostname, so http://example.com/foo/bar/
baz would be rewritten to http://www.example.com/foo/bar/baz

Walter

On Oct 6, 2010, at 1:05 PM, Dan J wrote:

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


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walt for the response, however it doesn’t work out for some reason. You’d think it would since it sits in the root “public_html” folder, but that subsite in a subfolder just won’t redirect with the www in front.

I’ll have to dig around and see what’s going on.


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How about the site in the main root folder? Does it redirect?

Walter

On Oct 9, 2010, at 4:20 AM, Dan J wrote:

Thanks Walt for the response, however it doesn’t work out for some
reason. You’d think it would since it sits in the root
“public_html” folder, but that subsite in a subfolder just won’t
redirect with the www in front.

I’ll have to dig around and see what’s going on.


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The site in the main folder does redirect to the www version.


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Try this, then. Find one of the pages in the subfolder, get the entire
URI of that page (including the filename, in other words) and see if
it redirects when you leave off the www. If that works, but trying to
get the index to load when you just put in the subfolder name and
nothing else, then I suspect what might be happening here is that
Apache is trying to do its magic redirect behavior (DefaultIndex), and
that’s side-stepping the other redirect.

Walter

On Oct 9, 2010, at 1:39 PM, Dan J wrote:

The site in the main folder does redirect to the www version.


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


offtopic mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options