1

Possible Duplicate:
How to identify if referrer is a 301 redirect

Using htaccess Im doing a 301 redirect to redirect old urls to the new urls, the issue is the url contains the id that is stored in the db. But I have a new db with new ids so now when the old url redirects to the new url a different record loads on the page. So what I did was store the old ids along with the new ids so I know what old id belongs to the new id. However how can I detect someone is trying to access the old url? Is there a way in php to detect the person coming to the page is being redirected via a 301? I dont want to add anything new to the url due to SEO reasons so I really need to know if I can detect if they came to this page via 301 redirect. Hope this makes sense.

4

4 回答 4

2

向重定向添加另一个参数,例如redirect=true,检查参数以让您的应用知道它是重定向,启动会话,然后再次重定向到最终的未更改 url,比较会话以了解用户来自重定向的 url .

或者按照萨尔曼的说法,使用规范的网址。

于 2012-12-08T19:54:38.307 回答
0

脚本不会知道某些内容是否已重定向到它。与其重定向到,不如说index.php?id=12345添加一个中间重定向,您可以在其中确定正确的 URL。

首先,使用临时变量名重定向您的 .htaccess,例如index.php?oldid=12345,然后在该脚本中执行以下操作:

if (isset($_POST['oldid'])) {
    $id = fetch_new_id();
    header("Location: index.php?id=$id");
}
于 2012-12-08T19:51:38.727 回答
0

我认为您无法检测到已设置的 http 状态,但是使用 .htaccess 您可以将其他变量添加到重定向的 url 或将 id 重命名为另一个变量名。

于 2012-12-08T19:53:13.130 回答
0

为什么不通过 php 处理所有旧 URL 加上重写,并让代码直接 301 重定向到具有新 id 的新 URL?

于 2012-12-09T00:49:30.490 回答