Permanent Redirect of "www"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Hagan
    Senior Member
    • Mar 2004
    • 724

    Permanent Redirect of "www"?

    My customer evidently ran his site through one of those "improve your page rank" analyzers, and came back with this:

    I was looking for ways to improve my page ranking and got this item:

    "Permanent Redirect Not Found

    Search engines may think www.yourdomain.com and yourdomain.com are
    two different sites.You should set up a permanent redirect (technically
    called a "301 redirect") between these sites. Once you do that, you will
    get full search engine credit for your work on these sites."
    I have never had to do this, and thought we were set up that way by default (and I find it odd that a search engine wouldn't be able to figure it out anyway).

    What do you think about this? And, how do I do this ... in .htaccess like I would do any redirect?
  • djn
    Senior Member
    • Mar 2004
    • 140

    #2
    As with everything regarding search engines, nobody has a definite answer but for those inside. What is certain is that search engines do not like duplicated content - i.e. the same content under different URLs. Well, one would suppose that they've already learned that example.com and www.example.com are just the same and not duplicated, but they don't tell. As all this costs you nothing, you may as well play it safe and do the redirect.

    To force a www in front of your domain name drop these lines into .htaccess:

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    The inverse is possible too:

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

    Comment

    • Frank Hagan
      Senior Member
      • Mar 2004
      • 724

      #3
      Thanks for the code; I'll bet it isn't necessary, but I went ahead and edited the .htaccess file to include it, and it works (you can check what the headers return on several sites, so I checked using http://news.stepforth.com/seo-tools/...er-checker.php)

      Comment

      • djn
        Senior Member
        • Mar 2004
        • 140

        #4
        And just when I was almost sure the matter was settled and closed this stuff sneaked up on me from behind, speaking softly and carrying a big cluebat:
        http://www.rooftopsolutions.nl/article/224 (Search engines to support 'canonical urls')

        Comment

        • Frank Hagan
          Senior Member
          • Mar 2004
          • 724

          #5
          Not sure that helps much ... for static html sites, you have to include the directive in every page in the head section? The .htaccess redirect you gave is obviously a better way to do it regardless of what content you have now or add in the future.

          Sometimes I wonder if Google is taking too many pages from Microsoft with creating their own standards.

          Comment

          • Camo.Fish
            Member
            • Jul 2008
            • 42

            #6
            I know this is old but..

            This is what I have been using for a long time:

            .htaccess
            RewriteEngine On
            # Remove www.
            RewriteCond %{HTTPS} on
            RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
            RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
            RewriteCond %{HTTPS} off
            RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
            RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
            # Translate Semantic to Get
            RewriteCond %{SCRIPT_FILENAME} !-f
            RewriteCond %{SCRIPT_FILENAME} !-d
            RewriteRule ^(.*) /index.php?url=$1 [L,QSA]

            *note* do not use that last part, it is just an example of proper canonical url rewriting.. i am a firm believer in http://no-www.org/ .. i haven't typed a www since the 90s except for sites that don't know how to properly configure their servers.

            Comment

            Working...