0

My HTACCESS code is this

ErrorDocument 404 /404.php

It is working well. What I want is when some one types a bad URL like (www.website.com/sometest.html)

In the case that "sometest.html" page does not exit and it will re-direct to the 404 page. But how can I detect what URL they typed? I want to get this: www.website.com/sometest.html

I have tried $_SERVER['HTTP_REFERER'] and $_SERVER["REQUEST_URI"]; both can't get the output that I'm looking for.

JAL
  • 41,701
  • 23
  • 172
  • 300

1 Answers1

1

Apache sets some environment variables for you. They were nice enough to let you know about it in the documentation.

Try using $_SERVER["REDIRECT_URL"] and $_SERVER["REDIRECT_QUERY"] in your script.

miken32
  • 42,008
  • 16
  • 111
  • 154
  • like here https://stackoverflow.com/questions/13666079/get-original-url-for-404-page $_SERVER["REDIRECT_URL"] worked for me. others where telling to use the referer but this is depending on the browser does send a referer and the server uses a location-header to redirect to the 404 page.. – René W. Jul 02 '17 at 19:36