Using htaccess to create a 301 error code
If you, as we just have, rebuild your website and, hence, the page names and architecture, you will need to tell Google where to find the equivalent of the pages it already has cached. If you just let your old website pages disappear without telling Google this information you will be leaving loads of dead ends, broken links, and losing loads of hard earned page ranking.
But if you add a few lines of code to your .htaccess file (assuming you are running Apache) you can tell Google that the pages it seeks have "Permanently Moved" by presenting it a 301 error code for each old page, and this is quite simply done.Redirect 301 /path/oldpage.html http://www.yoursite.co.uk/pathto/newpage.html
Now, if you also have, as we have had, an area structured with parent-child pages like this:
www.sputnikweb.co.uk/portfolio/
www.sputnikweb.co.uk/portfolio/first-project.html
www.sputnikweb.co.uk/portfolio/second-project.html
etc.
...you will need to structure your 301 statements such that the right lines are handed over to Google, or a user's browser first. If you structure your .htaccess file like this:
Redirect 301 /portfolio/ http://www.yoursite.co.uk/showpieces/
Redirect 301 /portfolio/first-project.html http://www.yoursite.co.uk/showpieces/project1.html
Redirect 301 /portfolio/second-project.html http://www.yoursite.co.uk/showpieces/project2.html
...you will find that the first line, which redirects requests for, in this example, the portfolio root page will get in there first and the subsequent lines will not be referred to at all. Consequently, a request for www.sputnikweb.co.uk/portfolio/first-project.html will be turned into a request for www.sputnikweb.co.uk/showpieces/first-project.html [incorrect], not http://www.yoursite.co.uk/showpieces/project1.html [correct]. To solve this, simply drop the 301 statement converting the directory root to the bottom of the list, thus:
Redirect 301 /portfolio/first-project.html http://www.yoursite.co.uk/showpieces/project1.html
Redirect 301 /portfolio/second-project.html http://www.yoursite.co.uk/showpieces/project2.html
Redirect 301 /portfolio/ http://www.yoursite.co.uk/showpieces/
This means requests for the child pages will be dealt with correctly before the parent directory gets resolved.




























