It's not clear to me if this url
www.mydomain.com/electronics/radio is just an alias for
www.mydomain.com/product.php?type=1&id=2 created by the same PHP script, or if they are two separate PHP scipts (even if they display out the same contents), the old script is product.php and the new PHP script is index.php
According to some of your comments
That is, there is already a index.php in each sub-folder to handle the
case where the entry is directly to /category/product page..
I would say we are in the 2nd case, so you have two separate PHP scripts.
What you need to do is to simply redirect the old pages i.e.
www.mydomain.com/product.php?type=1&id=2 to the new ones i.e.
www.mydomain.com/electronics/radio via a 301 permanent redirect.
Therefor you simply need to add this code at the top of
1. Look in your DB/code to find out:
- what category name corresponds to type=1 (in the example "electornics")
- and what item name corresponds to id=2 (in the example "radio")
I suppose you create a couple of functions getCategoryNameFromType/getItemNameFromId
in order to do this tedious job.
The functions return empty string when they don't find a correspondence
$category_name = getCategoryNameFromType( $_GET['type'] );
$item_name = getItemNameFromId( $_GET['id'] );
//if both not empty strings
if( $category_name && $item_name )
//2. Creating webpage url to redirect
$webpage = "http://www.mydomain.com/" . $category_name . "/" . $item_name . "/";
//3. Redirecting 301 permanent
header("Location: " . $webpage, TRUE, 301);