mod_rewrite的/ RewriteMap指令使用一个数据库查询脚本网址 [英] Mod_ReWrite / ReWriteMap a URL using a database lookup script

查看:220
本文介绍了mod_rewrite的/ RewriteMap指令使用一个数据库查询脚本网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景结果
我已经完全改写一个旧的现有ASP经典的电子商务网站到PHP。

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

previous站点的数据库设计具有关系ID问题很多导致产品数据行到其它表的麻烦联在数据库中。

The database design of the previous site had alot of relational ID problems causing troublesome linking of product data rows to other tables in the database.

要解决这个问题我还重新设计了数据库,赋予产品新的主键,同时仍保持在列表与旧产品的PK。

To get around this I also redesigned the database, giving products new Primary Keys, whilst still keeping a column in the table with the products old PK.

问题结果
我的问题是,当该网站重新启动,我需要用来指向所有的搜索引擎链接到Product.asp?的ProductID = 29'来查找数据库,符合产品的老PK,并重定向到新的产品PK即Products.php?ID = 53'。

The Problem
The problem I have is when the site is relaunched, I need all search engine links that used to point to 'Product.asp?ProductID=29' to lookup the the database, match the products old PK, and redirect to the products new PK i.e. 'Products.php?ID=53'.

我期待与mod_rewrite的/ RewriteMap指令要做到这一点,但是,所有的文件,我可以在网上找到的没有说明如何处理与数据库脚本PK查找。

I'm looking to do this with Mod_ReWrite/ReWriteMap, however, all documentation I can find online doesn't state how to deal with the database script PK lookup.

更新结果
/:我在 HTTP上伊格纳西奥巴斯克斯 - 艾布拉姆斯建议读了进一步/httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap >外部重写程序,这似乎是正确的,理想的解决方案。结果
然而,我的主机接触后,它们不会启用 RewriteMap指令在其服务器上。

Update
I've read up further on Ignacio Vazquez-Abrams' suggestion at http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap > External Rewriting Program, and it seems to be correct and the ideal solution.
However, after contacting my host, they do not enable ReWriteMap on their servers.

我提供我自己的,但绝不是没有 RewriteMap指令启用最好/正确实现这一目标的解决方案。

I've supplied my own, but by no means the best/correct solution of achieving this without ReWriteMap enabled.

推荐答案

找出 RewriteMap指令是我的主人残疾人,我已经达到了我自己的解决方案简单地使用<后code>的mod_rewrite 和2x 301重定向。

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

.htaccess文件

.htaccess file

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

SEO_Redirect.php文件

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']);

请注意,这是每一个文件的简化摘录,也不会反对SQL注入安全的。

Note, this is a simplified excerpt of each file, and would not be secure against SQL injection.

希望谷歌和都将接受越来越2X 301重定向没有问题。

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

这篇关于mod_rewrite的/ RewriteMap指令使用一个数据库查询脚本网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆