+ Reply to Thread
Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By danprobo
  • 1 Post By mario8

Thread: 301 redirect from non www to www

  1. #1
    danprobo's Avatar
    danprobo is offline x10 Sophmore danprobo is an unknown quantity at this point
    Join Date
    Jan 2009
    Location
    Indonesia
    Posts
    162

    301 redirect from non www to www

    We know that search engines have the ability to determine the www and non-www versions are the same and combine the results but occasionally it fails and we see both versions is indexed, and this is bad for the site owner since link benefit (PR/anchor text) is shared over two sites.

    Here's a few step to resolve this problems by editing the .htaccess file and write a permanent 301 redirect script on it:

    1. Go to your cPanel.

    2. Then File Manager

    3. Find your .htaccess file on public_html.

    4. Check the checkbox on .htaccess file.

    5. On toolbar click Edit.

    6. Write this script on your .htaccess file (the red ones and change the "example.com" with your domain name):

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


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


    7. After write the script then save it.
    8. Now try visit your site.


    Hope this helpful :naughty:

    Cheers

  2. #2
    nirajkum is offline x10 Sophmore nirajkum is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    161

    Re: 301 redirect from non www to www

    thanks danpro it was reallly useful . But the problem is that some hosting site dont provide cpanel

  3. #3
    danprobo's Avatar
    danprobo is offline x10 Sophmore danprobo is an unknown quantity at this point
    Join Date
    Jan 2009
    Location
    Indonesia
    Posts
    162

    Re: 301 redirect from non www to www

    A high PR website always do that, they will choose displaying their website as www or non www. Ya x10Hosting is the best
    dinomirt96 likes this.

  4. #4
    mario8's Avatar
    mario8 is offline x10Hosting Member mario8 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    5

    Smile Re: 301 redirect from non www to www

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    PHP Code:
    <?
    $ref
    =$_SERVER['QUERY_STRING'];
    if (
    $ref!=''$ref='?'.$ref;
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://newdomain.com/'.$ref);
    exit();
    ?>
    PHP Code:
    <?php
    header
    ("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.ru/newdir/newpage.htm");
    exit();
    ?>
    Last edited by mario8; 08-06-2009 at 09:23 AM.
    karimirt47 likes this.

+ Reply to Thread

Similar Threads

  1. Domain redirect fails
    By forum123 in forum Free Hosting
    Replies: 1
    Last Post: 08-25-2008, 11:26 PM
  2. sort of redirect help
    By galaxyAbstractor in forum Programming Help
    Replies: 4
    Last Post: 06-14-2008, 07:08 AM
  3. Redirect
    By BlueIce in forum Free Hosting
    Replies: 3
    Last Post: 10-21-2007, 09:06 AM
  4. Cpanel Redirect problem
    By BigEmmaFanz in forum Free Hosting
    Replies: 5
    Last Post: 12-10-2005, 05:51 PM
  5. How Do You Redirect?
    By TarinC in forum Off Topic
    Replies: 2
    Last Post: 10-02-2005, 12:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers