file.php?id=somevalue need redirecting to /folder/somevalue.php

Discussion in 'PHP' started by calcalmx123, Mar 10, 2014.

  1. #1
    Hey, after a little help here please I know its bad for SEO having duplicate pages and after flicking a few pages in to a 'Site:' search on google I've found that Google has indexed both urls so I need a permanent redirect from 'file.php?id=somevalue' to '/folder/somevalue.php' so Google will remove the duplicates from its search engine.
     
    calcalmx123, Mar 10, 2014 IP
  2. loop

    loop Active Member

    Messages:
    519
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    90
    #2
    with .htaccess:

    RewriteEngine On
    RewriteRule ^file.php?id=(.*) folder/$1.php

    with PHP:

    if($_GET['somevalue']){
    header("Location: folder/".$_GET['somevalue'].".php");
    }
     
    loop, Mar 10, 2014 IP
    calcalmx123 likes this.
  3. tutorialsscripts

    tutorialsscripts Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    tutorialsscripts, Apr 12, 2014 IP
  4. Mr Lee

    Mr Lee Greenhorn

    Messages:
    27
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    20
    #4
    That or make an alias directory . Then only the server knows it is one file. EVeryone else sees 2 files from 2 different directories.
     
    Mr Lee, Apr 14, 2014 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    If you want search engines to de-list the old one, a rewrite rule without any parameters -- such as that provided by @loop isn't going to do it; the page will load transparently as if it still exists! Completely missing the point :D

    Redirect 301 ^file.php?id=(.*) folder/$1.php
    Code (markup):
    or

    RewriteEngine On
    RewriteRule ^file.php?id=(.*) folder/$1.php [L,R=301]
    Code (markup):
    A 301 Permanently moved on the other hand... that should do what you are asking.
     
    deathshadow, Apr 17, 2014 IP