Override http status code from 404 to 200

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

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

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

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

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);

but response code is still 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


I've found a strange feature using htacess for sending my own 404 page and maybe there is a "search" to do in this direction: if you create a htacess with this:

  ErrorDocument 404 /my_page.php

the browser will receive the content of my_page.php wih a 404 header. And it seem you can't change the response code.

But if you write in the htacess:

  ErrorDocument 404 http://www.mys_site.com/my_page.php

so an absolute URL, the browser will receive my_page.php with a 200 header. I use that to fool "hacker robots" who try to access pages and look at the header to see if they've find or not the page they are looking for.

Maybe using this in your htaccess to detect the page which is called, can help you.

链接地址: http://www.djcxy.com/p/45614.html

上一篇: 如何使用java删除或隐藏Http响应错误

下一篇: 覆盖http状态码从404到200