how to 301 redirect all the backlinks to the homepage?

NemoWouldNeverM

New member
May 19, 2011
30
2
0
What htaccess trick are you all using to redirect existing backlinks to the homepage?

I searched here, but didn't quite find what I was looking for: .Htaccess rewrites, Mod_Rewrite Tricks and Tips

The site is a blog (on a PR2 domain I bought). I'm adding new posts to it, so I want the permalinks on the blog to work, while redirecting (301) the non-existent pages to the homepage.

This is done with .htaccess, right? Or do you overload the 404 page for this?
 


in .htaccess

Code:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

in index.php

PHP:
<?php
$uri = substr($_SERVER['REQUEST_URI'],1);
if ($uri != '') {
header("Location: http://www.site.com",NULL,301);
exit;
}

// include other content here

?>
 
  • Like
Reactions: Scheme
For redirects using a 301 redirect in the htaccess file is the best option that works well for me. If you are using Wordpress then there is a plugin by the name of "301 redirect" using this you can enter the name of the URL to which you want to redirect to.