Search code examples
phphttp-status-code-404http-status-codes

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.


Solution

  • 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