The Scenario
I've completely rewritten a classic existing ASP classic ecommerce website to PHP.

The database style of the prior site had a lot of relational ID problems leading to difficult connecting of product data rows with other tables within the database.

To obtain for this I additionally remodeled the database, giving items new Primary Secrets, although still keeping a column within the table using the items old PK.

The Issue
The issue I've happens when the website is relaunched, I want all internet search engine links that accustomed to indicate 'Product.asp?ProductID=29' to research the the database, match the items old PK, and redirect towards the items new PK i.e. 'Products.php?ID=53'.

I am searching to get this done with Mod_ReWrite/ReWriteMap, however, all documentation I'm able to find online does not condition how to approach the database script PK research.

I have educate yourself further on Ignacio Vazquez-Abrams' suggestion at > Exterior Spinning Program, also it appears to become correct and what you want.
However, after getting in touch with my host, they don't enable ReWriteMap on their own servers.

I have provided my very own, but in no way the very bestOrappropriate solution of accomplishing this without ReWriteMap enabled.

Your query:


After that just echo the need for ID along with a newline, and flush stdout.

Rewrite rules:

RewriteMap dbfixup prg:dbfixup.script
RewriteCond %{QUERY_STRING} ProductID=(\d+)
RewriteRule Product.asp Products.php?ID=${dbfixup:%1}

You ought to have another get variable reputation for the brand new ID. That means by your brand-new program you will be aware whether or not to match the merchandise while using old ID or even the brand new one.

$old = isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0 ? $_GET['id'] : 0;
$new = isset($_GET['new']) && is_numeric($_GET['new']) && $_GET['new'] > 0 ? $_GET['new'] : 0;
if ($old + $new > 0) {
    $query = 'SELECT * FROM `ProductDetails` WHERE '.($old > 0 ? '`OrigPrdID`='.$old : '`PrdDetID`='.$new).' LIMIT 1;';

After discovering RewriteMap is disabled by my host, I have arrived at my very own solution simply using mod_rewrite and 2x 301 redirects.

.htaccess file

RewriteEngine on
RewriteRule ^Product(.*)\.asp SEO_Redirect.php [NC,R=301]

Search engine optimization_Redirect.php file

$ID = $_GET['ID'];

$query_rsNewID = "SELECT NewProductID FROM Products WHERE OldProductID = '$ID'";
$rsNewID = mysql_query($query_rsNewID, $Database);
$row_rsNewID = mysql_fetch_assoc($rsNewID);

header ('HTTP/1.1 301 Moved Permanently');
header ('Location: Product.php?ID='.$row_rsNewID['NewProductID']);

Note, this can be a simplified excerpt of every file, and wouldn't be secure against SQL injection.

Hopefully Google and alike need getting 2x 301 redirects without problems.