将HTTP状态码从404覆盖到200 [英] Override http status code from 404 to 200

查看:76
本文介绍了将HTTP状态码从404覆盖到200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我网站的所有页面都可以通过2个网址访问:一个是普通英语,另一个是IDN.示例:

All pages of my website will be accessible by 2 urls: one is normal english and one - IDN. Example:

www.example.com/examplepage
пример.рф/примерстраницы

在服务器上,我只有英文文件,所以我决定在php中创建2个数组:

On server I just have english files, so I decided to create 2 arrays in php:

$realUrl=array('examplepage');
$fakeUrl=array('примерстраницы');

并检入404.php文件:如果用户从$ fakeUrl数组请求URL-我只是从$ realUrl包含一个页面并将http状态代码更改为200(没有重定向,因此他在地址栏中看到了IDN请求).这是个好方法吗?一切正常,但我无法更改此类页面的响应代码,我已经尝试了两种方法:

And check in 404.php file: if user requests url from $fakeUrl array - I just include a page from $realUrl and changes http status code to 200 (NO redirect, so he sees his IDN request in address bar). Is it a good way? Everything works but I am not able to change a response code of such page, I've tried both:

header("HTTP/1.1 200 OK");
http_response_code(200);

但响应代码仍为404.

but response code is still 404.

推荐答案

您不能这样做,您需要重定向到真实URL或要求您的页面在同一页面中服务器.您还可以使用curl来确定该页面是否存在,但在404中不存在

You can't do that you need to redirect to the real URL or require your pages if they are in the same server. You can also use curl to determine if that page exists But not in 404

这篇关于将HTTP状态码从404覆盖到200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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