Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

non-www/www and subdirectory

3:33 pm on Dec 23, 2007 (gmt 0)

New User

10+ Year Member

joined:Sept 2, 2006
posts: 27
votes: 0

I have read a lot of threads about this subject, but still don't know how to tackle this situation :(

When performing an analysis via websitegrader I'm told that: "Permanent Redirect Not Found
Search engines often regard www.example.com and mysite.com as two different websites unless you take specific measures to signal to them that they are the same site. "

What I have is this redirect:
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ http://www.example.com/oscommerce/ [R=301,L]

So what I want to achieve is that any call be it www.example.com, example.com, www.example.com/oscommerce, example.com/oscommerce all goes to www.example.com/oscommerce. This works from a user point fine, but seemingly there is a problem from a search engine point of view.

From another post I can see that this syntax should be good:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

To achieve the above objective, could anyone please advise exactly what to white in my .htaccess file?

Thanks :)

[edited by: jdMorgan at 6:20 pm (utc) on Dec. 23, 2007]
[edit reason] example.com [/edit]

6:19 pm on Dec 23, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

In example.com/.htaccess, I'd use:

# Redirect domain root to /oscommerce
RewriteRule ^$ http://www.example.com/oscommerce/ [R=301,L]
# Redirect all non-canonical domain requests to canonical domain
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I can't say I agree with using an external redirect from "/" to /oscommerce/ -- An internal rewrite would seem to be more appropriate, and would "hide" the /oscommerce part of the URL. But I'm not sure if OSC would work properly that way -- Hopefully, someone else can comment on the intricacies of its installation and operation.

I deleted your first RewriteCond, since it wasn't doing anything at all except wasting CPU time.

You may also want to look into adding additional canonicalization rules -- For example, redirecting requests for /index.html (or index.php) to "/" -- What you may need depends on your site and the URLs it uses.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].


12:54 am on Dec 24, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
votes: 0

I always avoid redirectinhg from "/" to "/folder/" and much prefer to have a content page at "/".

If /folder/ contains a dynamic site, then "/" is usually a static page introducing the site and main navigation.

7:32 am on Dec 24, 2007 (gmt 0)

New User

10+ Year Member

joined:Sept 2, 2006
posts: 27
votes: 0

Thanks for your replies. However, how do I make an "internal rewrite" so that it appears to the visitors that they always are in www.mysite.com and does not see www.mysite.com/oscommerce? I agree that the latter would be much better.

Also, would this have any implications for the usefulness of saved urls containing /oscommerce and not least search engine rankings?