404 Error No Referrer
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Get page referer and missing page that generates Error 404 using PHP up vote 0 down vote favorite I've been researching online for a way to retrieve the URL that generates a 404 error. I've found various postings on this subject in this and other sites and tried them all. Unfortunately I'm still not being able to get what I want. So, if you could bare with me, I will try to explain what I've done and what I'm getting. SCENARIO: I have a page. Let's call http://www.example.com/index.php. In this page, I have a link, to let's say wrong_page.php or, if you prefer, http://www.example.com/index.php. As the page wrong_page.php doesn't really exists, When someone click on this link, it redirects to error404.php. (to make it easier, all pages are in the root directory. Question: Is it possible for error404.php to give me both index.php as the original page where the wrong link resides and wrong_page.php as the wrong link itself? SETUP At the root folder of my site I have .htaccess file with the following directive: ErrorDocument 404 error404.php Inside error404.php I loop through the whole $_SERVER variable and, this is what I get: If the visitor clicks on the wrong_link (the one that leads to wrong_page.php), I get $_SERVER['HTTP_REFERER'] = 'index.php' but no reference to wrong_page.php; If the visitor types wrong_page.php in the address bar, $_SERVER['HTTP_REFERER'] doesn't even exist (tested with isset() function). Moreover, in both cases $_SERVER['REQUEST_URI'] = 'error404.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to find referrer URL while using htaccess 404 redirect? up vote 2 down vote favorite I've used the code below to create a custom 404 message (page not found) using http://stackoverflow.com/questions/24922104/get-page-referer-and-missing-page-that-generates-error-404-using-php a .htaccess file. RewriteEngine On ErrorDocument 404 https://%{HTTP_HOST}/404.php It works well, but I want to know what was the wrong URL that caused this redirection. In other words, I need to fetch HTTP referer while user is in 404.php. So I have used $_SERVER['HTTP_REFERER'] in 404.php, but it does not return anything. Where did I have mistakes? And what is your solutions to solve this problem? php apache .htaccess http-referer share|improve this question edited Nov 9 '15 at 8:27 http://stackoverflow.com/questions/33603853/how-to-find-referrer-url-while-using-htaccess-404-redirect anubhava 380k32159231 asked Nov 9 '15 at 6:51 Mohammad Saberi 3,966154381 Don't trust the referrer-header. Some (qutie a lot) browers/routers/vpns/firewalls actually clears the referrer-header for privacy reasons. –Magnus Eriksson Nov 9 '15 at 6:57 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted Remove http:// from 404 handler and have it like this: ErrorDocument 404 /404.php The URL that is causing 404 is available to you in 404.php using: $_SERVER["REQUEST_URI"] When http:// ise used in 404 handler server performs full redirection and you loose original REQUEST_URI. share|improve this answer answered Nov 9 '15 at 6:56 anubhava 380k32159231 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged php apache .htaccess http-referer or ask your own question. asked 10 months ago viewed 307 times active 10 months ago Linked -2 Error 404 Pages Related 1Redirect url using .htaccess (Multiple special characters)0.htaccess Rules Removing .php while forwarding real 404s1i want to output on 404 page the url the user was trying to use that resulted in the 404 page2404 Error Page
from GoogleSign inHidden fieldsSearch for groups or messages