30 .. redirection ..

Discussion in 'Search Engine Optimization' started by Toon-c, May 15, 2009.

  1. #1
    Toon-c, May 15, 2009 IP
  2. rv12may

    rv12may Peon

    Messages:
    292
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use this code at your site index page source code in head "<script language="JavaScript" type="text/JavaScript" src="redirection.js"></script>
    " after that create a page http://www.xyz.com/redirection.js

    in which put this code

    url = window.location.href;
    var valid = "w"
    var len=url.length;
    var chk=url;
    for(i=0;i<len;i++)
    {
    x = chk.charAt(i)
    if(!(valid.indexOf(x) == -1))
    {
    //found
    var red = "no"
    i = len;
    }
    }
    if(red != "no")
    {
    location.href=("http://www.xyz.com");
    }
     
    rv12may, May 15, 2009 IP
  3. Canonical

    Canonical Well-Known Member

    Messages:
    2,223
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I would NOT recommend trying to use javascript to fix canonical issues (which is what you have if your pages can be accessed with and without www). Search engine crawlers do not execute javascript so they will never see the redirect above. The above javascript might fix it in the browser for site visitors, but they could care less whether you have canonical issues or not. It's the spiders/crawlers you need to fix it for.

    You need to use Mod Rewrite or something like it to implement 301 redirects. You will have access to this if you're hosted on an Apache web server. You should be able to create a .htaccess file in the root of your web with something like the following to redirect:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /

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

    I'm just winging this... haven't tested it and it's late... You can Google "fix canonical issues with mod rewrite" to get more examples.
     
    Canonical, May 15, 2009 IP