Mobile app version of vmapp.org
Login or Join
BetL925

: One to many problem with implementing 301 redirect after changed urls I have a problem. I had an old dynamic url which I have now split into multiple static urls. e.g. www.mydomain.com/product.php?type=1&id=2

@BetL925

Posted in: #301Redirect #Seo

I have a problem.
I had an old dynamic url which I have now split into multiple static urls.

e.g.
mydomain.com/product.php?type=1&id=2 www.mydomain.com/product.php?type=2&id=3 mydomain.com/product.php?type=2&id=4, etc


which I have changed to something like
mydomain.com/electronics/radio www.mydomain.com/electronics/television mydomain.com/mobile/smartphone, etc.


Google has previously indexed the dynamic urls and search results show the old urls. I want search to point to the new urls.

I have kept the old url active, so both urls work.

How can I set up a 301 redirect in this case? I run IIS and it only allows a page to be redirected to 1 url.

Should I deactivate the old dynamic url? In that case I lose all the previous seo rankings..

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @BetL925

3 Comments

Sorted by latest first Latest Oldest Best

 

@Dunderdale272

It's not clear to me if this url mydomain.com/electronics/radio is just an alias for 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. mydomain.com/product.php?type=1&id=2 to the new ones i.e. mydomain.com/electronics/radio via a 301 permanent redirect.

Therefor you simply need to add this code at the top of product.php script:

<?php

/*
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);
exit();
}

?>

10% popularity Vote Up Vote Down


 

@Gail5422790

It could be a bit of work, but you shouldn't have old dynamics url created anymore.

Then you can redirect each old dynamic url (their number is limited).

10% popularity Vote Up Vote Down


 

@Goswami781

you could leave product.php as it is (displaying product base on type and id) but add categoryname and productname GET variables (and code to map them to an actual product), so you can redirect the new type of url mysite.com/(category)/(product) to product.php?categoryname=&productname=
I don't know ISS so I cant suggest the actual code for the rule

EDIT: I think I misunderstood your question at first. The way I do it is adding something like this in PHP (i see you are using PHP, but you could do similarly in any language):

if (strpos($_SERVER['REQUEST_URI'],'/product.php') === 0)
{
// redirect to mydomain.com/category/product/ }

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme