duanjiao3686 2011-10-25 14:53
浏览 96
已采纳

PHP 410重定向

I'm using WordPress and I would to redirect all unauthorized users to the homepage.

In order to do so in the header file I put (at the begin of the file) the following PHP code:

if (bp_current_component() != "" 
    && bp_current_component() != "event" 
    && !is_user_logged_in() 
    && !isset($_COOKIE[affiplus]) 
    && !isset($_GET[affid]))
{
    header( "HTTP/1.1 410 Gone" ); 
    header( "Location: ".get_option('siteurl')."/home/");
}

Unfortunately the HTTP error code returned is always 302 (Moved permanently) and not 410 as I want. Why?

  • 写回答

3条回答 默认 最新

  • dongtuliao6760 2011-10-25 14:55
    关注

    You can only send one response status code. So you can either send an error response (4xx) or a redirection response (3xx). Sending a 410 header when an unauthorised user tries to access a resource would be incorrect anyway.

    I think just performing a 302 is more than adequate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析