www.webdeveloper.com
Results 1 to 7 of 7

Thread: Redirect indexed subpage to www.mydomain.com

  1. #1
    Join Date
    Jul 2004
    Posts
    126

    Redirect indexed subpage to www.mydomain.com

    Hi,

    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.

    I've looked at different javascript solutions, but they all require frames (which I'm not using). Also had a look at some rewrite rules that can be set for Apache servers, but didn't quite understand that stuff.

    Would appreciate any help with this.

    Thanks!
    Mago

  2. #2
    Join Date
    Sep 2003
    Location
    Portsmouth, UK Occupation: Web Developer
    Posts
    2,602
    you could try

    PHP Code:
    if(document.referrer != "http://www.mydomain.com/index.php") {
    window.location 'http://www.mydomain.com/';

    wont work if you have JS disabled or Referrer Logging Disabled though
    Richard Turner - A Virtual Insight

  3. #3
    Join Date
    Jul 2004
    Posts
    986
    I'd return to Google and resume my search if I visited your site and was redirected to your index.php instead of the specific document I was looking for...

    Gheesh, you may as well remove yourself from Googles listings...

    .....Willy

  4. #4
    Join Date
    Sep 2003
    Location
    Portsmouth, UK Occupation: Web Developer
    Posts
    2,602
    o yes same here, not sure what the purpose is, but the above code will do waht you want
    Richard Turner - A Virtual Insight

  5. #5
    Join Date
    Jul 2004
    Posts
    126
    Well, the problem is that google is indexing some of my popup html-pages and without the info on their parent pages they make absolutely no sense at all.

    Do you think the javascript code might cause any problems concerning the indexing of my pages at google?
    Mago

  6. #6
    Join Date
    Jul 2004
    Posts
    986
    Originally posted by mago
    Do you think the javascript code might cause any problems concerning the indexing of my pages at google?
    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...

    .....Willy

  7. #7
    Join Date
    Jul 2004
    Posts
    126
    96turnerri,

    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?):

    <script language="javascript">
    if(document.referrer.indexOf("www.mydomain.com/")==-1 && document.referrer!=""){
    window.location.href="http://www.mydomain.com/index.php"; }
    </script>

    However, can't figure out what the underlined part means. Seen it both with -1 and with 0. And why two & and not only one?
    Mago

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles