pimpjohnson Posted December 1, 2009 Share Posted December 1, 2009 Hi. I've been searching up and down and reading docs and testing theories but none of my solutions work on this issue. Let's say a user TYPED in a url on your site ( www.yoursite.com/page.html ) but, of course, when it doesn't exist they will get redirected to the 404 page. But, I'm trying to get the 'desired' url (i.e. what they typed in) but all that gets returned in the server vars is the 404 file itself or blank values, and not what was typed in. I've used $_SERVER["REDIRECT_URL"], $_SERVER["REQUEST_URI"], INFO_VARIABLES and I've even tried printing out all of the variables with phpinfo(), but my result always shows the 404 page as the REQUEST_URI and there's no mention to the non-existent file I'm looking for. And again, this is only when the URL is typed in the address bar incorrectly (not from clicking on a link). I've tried Java and PHP but I can't find a solution to get me what was typed in (other than my own 404 page). My Goal: Basically if someone types in the domain.com/KEYWORD, I want to be able to take the typed url, grab the trailing keyword, and parse my database for a matching item or page (or something similar) and refer them to that page instead of directly sending them a 404 page. If anyone has an idea or has run into this problem themselves or even a link to a working doc, I'd appreciate it. In the mean time I'm going to continue to try out some things and post a solution if I can find one. Thanks in advance, -PJ Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 Where exactly is all this taking place? If you write your code within a customized 404 page you should have no trouble capturing the data your looking for. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 1, 2009 Share Posted December 1, 2009 A custom 404 page ( that you assign through .htaccess ) can use PHP to send the typed URL into a database or whatever you wish. Note that the Apache log will have ALL access, so you can use a parser or a log reading interface to view the pages that 404'd already. Quote Link to comment Share on other sites More sharing options...
pimpjohnson Posted December 1, 2009 Author Share Posted December 1, 2009 Where exactly is all this taking place? If you write your code within a customized 404 page you should have no trouble capturing the data your looking for. Thanks for the reply. Yes it's a custom 404 page. Here's the actual test code I've been using to remedy the problem: <?php echo $_SERVER['REQUEST_URI'] . " << This is the requested URL"; ?> But when I type in anything the result is /my404.php << This is the requested URL . I won't be surprised if there's something I overlooked. I'm a C++ guy but I know my way around PHP for the most part but every once in a while...This really shouldn't even be a problem you know? Any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
pimpjohnson Posted December 1, 2009 Author Share Posted December 1, 2009 A custom 404 page ( that you assign through .htaccess ) can use PHP to send the typed URL into a database or whatever you wish. Note that the Apache log will have ALL access, so you can use a parser or a log reading interface to view the pages that 404'd already. Thanks for the reply. Yeah, this 404 is assigned through .htaccess but I'm still getting undesired results. I wouldn't mind using a log file either. But at the moment the only thing I can find is an error log and all it has is a parse error from a few months back. I'll keep looking and thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 It would be the $_SERVER['HTTP_REFERER'] variable your after. Why not dump the $_SERVER array and see whats there? echo '<pre>'; print_r($_SERVER); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
pimpjohnson Posted December 1, 2009 Author Share Posted December 1, 2009 It would be the $_SERVER['HTTP_REFERER'] variable your after. Why not dump the $_SERVER array and see whats there? echo '<pre>'; print_r($_SERVER); echo '</pre>'; LOL, well I tried the $_SERVER['HTTP_REFERER'] earlier and it's still returning a blank: Result now reads << This is the requested URL And I dumped the server earlier too. The current result is still [REQUEST_URI] => /my404.php [sCRIPT_FILENAME] => /home/jworkss1/public_html/my404.php [sCRIPT_NAME] => /my404.php for my relevant variables. Head scratcher... Quote Link to comment Share on other sites More sharing options...
pimpjohnson Posted December 1, 2009 Author Share Posted December 1, 2009 BTW, I just created a blank 404 file with the code snippet you gave me (thorpe) and I created a new .htaccess file to point to it too. Still same result, it's just returning the 404 file name (404.php now) Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2009 Share Posted December 1, 2009 Can we see the .htaccess entry? It looks like your redirection might be clearing your variables somehow. Quote Link to comment Share on other sites More sharing options...
pimpjohnson Posted December 1, 2009 Author Share Posted December 1, 2009 No need thorpe, I found the issue! Actually it was my .htaccess file. In it I had ErrorDocument 404 http://www.fitswear.com/my404.php And I made the change to ErrorDocument 404 /my404.php -- no HTTP folks! My mistake. I set it up 2 years ago and it worked fine for redirections, but when I tried to do more with my 404 it blew up in my face. But thanks to you and oni-kun for losing a little sleep over this with me. I think I'm gonna put this on one of my t-shirts now lol (it's a t-shirt site btw). Thanks again, -PJ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.