I've been trying to find a way to redirect my users from my subpages to my index page when accessing the pages from e.g. google.
For example, I only want www.mydomain.com/folder/somefile.htm to be accessible from www.mydomain.com. And when users are clicking on www.mydomain.com/folder/file.htm in the Google result list I want them to be redirected to www.mydomain.com/index.php.
Originally posted by mago
Let's hope so, because I'm sure most people will not appreciate being redirected from where they believed they were going... What do you expect your visitors coming from Google to do, start searching your site for the document they were looking for... I don't think so and all you will have done is waste their time...
You are going about this the wrong way... I would suggest that you read up SEO (search engine optimization) and look into NO-INDEX/NO-FOLLOW as well as placing those pages you do not wished indexed into a directory protected by .htaccess to keep the bots out...
But redirecting will only serve to drive your visitors away...
I tested your script and it works fine. Only problem is that if I use != "http://www.mydomain.com/index.php" then I can't access www.mydomain.com/folder/file.htm from e.g. http://www.mydomain.com/index.php?page=1.
Using your example, I managed to find this piece of code (which should do the trick, right?):