Mod_ReWrite / ReWriteMap a URL using a database lookup script

前端 未结 3 734
[愿得一人]
[愿得一人] 2021-01-17 04:40

The Scenario
I have completely rewritten an old existing ASP classic ecommerce website over to PHP.

The database design of the previous site had

3条回答
  •  梦谈多话
    2021-01-17 05:00

    After finding out RewriteMap is disabled by my host, I've reached my own solution simply using mod_rewrite and 2x 301 redirects.

    .htaccess file

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

    SEO_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 is a simplified excerpt of each file, and would not be secure against SQL injection.

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

提交回复
热议问题