php - 如何识别 referrer 是否是 301 重定向

标签 php apache mod-rewrite http-status-code-301

我目前正在为我的网站实现一个 slug 系统。我计划将无效的 slug 重定向到存储在数据库中的正确位置。 例如

http://example.com/11/wrong-slug

Hit db, check if 11's slug is wrong-slug if not do 301 redirect

http://example.com/11/right-slug

Detect 301 and inform user that they followed an invalid link

是否可以最好使用 PHP 识别 301 重定向,以便我可以要求用户更新那里的书签等。

谢谢, 杰米。

最佳答案

或者,您可以将 GET 参数附加到您的 url(如果您不介意的话),并在您的 PHP 脚本中检查它。像这样的东西:

http://example.com/11/right-slug?corrected-from=http://example.com/11/wrong-slug

同样注意,您可以使用 session 或 cookie,但必须注意在检测到后将其删除。

关于php - 如何识别 referrer 是否是 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1963328/

相关文章:

apache - Htaccess : URL Rewriting not causing 404 on nonexisting pages and not working as expected

php - 通过 sql 命令和循环检索 php 中的编辑值 [php] [sql]

php - 安装/激活运行 MAMP 的 PHP "intl"扩展

.htaccess - htaccess 重定向追加查询字符串?

php - 使用 NGINX 作为 apache 的反向代理时,Wordpress 永久链接返回 404

java - Apache负载均衡——如何控制访问哪台服务器?

regex - 使用 HTTP_HOST 来识别识别以前的主机名

php - 如何将php代码放入jquery函数中

php - Select2 Ajax不匹配结果

php - 使用 Laravel 管理文件夹访问的最佳方式