用于确定用户是否301重定向到我的站点的PHP代码 [英] PHP code to determine if a user was 301 redirected to my site
问题描述
PHP是否可以知道用户是否已被重定向到我的网站?
Is it possible in PHP to know if a user has been 301 redirected to my website?
所以在 myoldsite.com 我有.htaccess文件中的301重定向到 mynewsite.com 。
So in myoldsite.com I have a 301 redirect in the .htaccess file to mynewsite.com.
我可以在 mynewsite.com中放置一些PHP代码识别用户何时被重定向?如果是这种情况,我只需要显示一条特定的消息。
Can I place some PHP code in mynewsite.com to recognise when a user has been 301 redirected? I just need this to display a specific message if this is the case.
非常感谢这里的任何指针: - )
Many thanks for any pointers here :-)
推荐答案
我相信301重定向 HTTP_REFERER
字段将包含原始引用:
I believe with 301-redirects the HTTP_REFERER
field will contain the original referer:
- 用户在地址栏中输入oldsite.com,301重定向到newsite.com
- referer =
- referer =3rdparty.com
这种行为在301重定向中有一定意义。
This behavior somewhat makes sense for 301 redirects.
解决方案:我认为你应该在你的301响应中添加一个查询字符串参数,例如
ref = oldsite
并在新网站上查看其价值。Solution: I think you should add a query-string parameter to your 301 response such as
ref=oldsite
and check its value on your new website.如果您担心网址中有查询字符串参数,你可以告诉搜索引擎忽略speci fic查询字符串参数。该程序因搜索引擎而异。显然有一个适用于所有主要搜索引擎的技巧:
< link rel =canonical>
代码。示例:If you are concerned about having query string parameters in your URLs, you can tell search engines to ignore specific query string parameters. The procedure varies with search engines. Apparently there is a trick that works across all major search engines: the
<link rel="canonical">
tag. Examples:-
http://newsite.com/?ref=oldsite
-
http://newsite.com/
http://newsite.com/?ref=oldsite
http://newsite.com/
-
http:/ /newsite.com/?page=main
http://newsite.com/?page=main
这篇关于用于确定用户是否301重定向到我的站点的PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-