如何确定是否引用是301重定向 [英] How to identify if referrer is a 301 redirect

查看:118
本文介绍了如何确定是否引用是301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施蛞蝓系统为我的网站的时刻。我计划存储在数据库中,以无效蛞蝓重定向到正确的。
例如。

I'm implementing a slug system for my website at the moment. I plan to redirect invalid slugs to the correct on that is stored in the database. E.g.

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

命中分贝,检查11的鼻涕虫是错误的,如果塞不能做301重定向

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

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

检测301,并告知他们遵循的无效链接的用户

Detect 301 and inform user that they followed an invalid link

是否有可能pferably使用PHP,所以我可以要求用户更新有识别301重定向$ P $书签等。

Is it possible to identify the 301 redirect preferably using PHP so I can ask the user to update there bookmark etc.

谢谢,
杰米。

Thanks, Jamie.

推荐答案

几种解决方案浮现在脑海中:

Several solutions come to mind:


  1. 你可以用 get_headers尝试() 啊不,它分派到URL的请求,这是不是你想要的

由于要重定向反正测试从同一台机器重定向,你可以简单地写一本关于错塞消息发送到用户的会话,并显示下一次视图模板呈现它。许多框架都有的闪光信使的组件,允许你这样做很容易,例如与Zend框架,你可以使用下面的code在你的控制器动作

Since you are redirecting and testing for the redirect from the same machine anyway, you could simply write a message about the wrong slug into the user's session and display it the next time the view template is rendered. Many frameworks have a flash messenger component, that allow you do that easily, e.g. with Zend Framework you would use the following code in your controller action

$ flashMessenger = $这个 - > _ helper->调用getHelper('FlashMessenger');
$ flashMessenger->方法addMessage(我们的确在最后一个请求的东西');

$flashMessenger = $this->_helper->getHelper('FlashMessenger'); $flashMessenger->addMessage('We did something in the last request');

而不是当一个错误蛞蝓发现立即重定向,你只呈现,告诉用户关于错误的蛞蝓视图模板,然后将元或JavaScript模板重定向。另外,您还写会用正确的蛞蝓到模板普通链接。

Instead of redirecting immediately when a wrong slug is found, you just render a View template that tells your user about the wrong slug and then use a meta or javascript redirect from the template. Optionally, you'd also write a plain link with the right slug to the template.

最后,您还可以通过的头(),然后可以从你的脚本读取。将不能工作,因为他们将失去,一旦浏览器从服务器得到了重定向

And finally, you could also inject a custom header into the redirect via header(), which can then be read from your script. won't work either, because they will be lost once the browser got the redirect from the server

这篇关于如何确定是否引用是301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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