0

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.

  • Instead of using the 404 page, you should probably redirect all traffic to a "normal" page and analyze / process the request there. – jeroen Jan 14 '17 at 09:33
  • @jeroen but I want to maintain the request url. Oh. Another way is to fisically create all files from $fakeUrl array and use include there.. :( – Michael Moor Jan 14 '17 at 09:52
  • You should maintain the requested url. Take a look into url rewriting, that way you can direct all traffic to non-existing pages to one script and handle the request there based on the requested url. – jeroen Jan 14 '17 at 09:53

3 Answers3

0

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

Abdalla Arbab
  • 1,360
  • 3
  • 23
  • 29
  • You can use curl to check if that page is available or not – Abdalla Arbab Jan 14 '17 at 10:08
  • The code you are trying to use can't be executed because you are sending the user to 404 you need to redirect the user to a page and start depug the page but you can't do that in 404 – Abdalla Arbab Jan 14 '17 at 10:38
0

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.

Peter
  • 1,247
  • 19
  • 33
0

This works How can I replace Apache HTTP code 404 to 200

<?php header("Status: 200 OK"); ?>

This code has to be put at the top of the .php file in the first line of code. Search engines, crawlers, browsers and anyone accessing the site will see the errordocument 404 page as a header 200.

Header 200 means the page exists. Google will crawl and index sites with header status 200.

human
  • 467
  • 4
  • 6