Results 1 to 3 of 3

Thread: [RESOLVED] How to Retrieve Invalid URL ??

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    6

    Resolved [RESOLVED] How to Retrieve Invalid URL ??

    Dear all, I need some help on this:

    Basically what i want to do is, whenever a visitor enters an invalid URL, I would like to redirect to a php file, and then I would like to retrieve the invalid URL and do some string manipulation with it.

    Let's say visitor type www.mydomain.com/blahblahblah , which is an invalid url. In stead of the standard "404 not found" page, i want all 404 request to be redirected to a php file, and get the whole "www.mydomain.com/blahblahblah" string for some processing.

    So far I've managed to make the redirection thing works by adding

    ErrorDocument 404 /somefile.php

    in my apache configuration file. However, I can't get the invalid URL. I try to get it from getenv("HTTP_REFERER"); but it's empty.

    Any ideas on how to achieve this? Thanks a lot !

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: How to Retrieve Invalid URL ??

    In your somefile.php error script use the REDIRECT_URL variable to get the bad file that was requested.

    Like this:
    PHP Code:
    //in the error php script that handles 404 errors

    echo $_SERVER['REDIRECT_URL']; 
    You can also use the REQUEST_URI server variable.

    That will output the bad file on the error page. Note it does not include the domain name, so for example it would return "/blahblahblah"

    Last edited by the182guy; Nov 12th, 2008 at 06:09 AM.
    Chris

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    6

    Re: How to Retrieve Invalid URL ??

    OK, I've fix the problem!

    At first I used:
    ErrorDocument 404 http://localhost/..../myphp.php

    Which the Apache server acts to REDIRECT to the page, not include it for processing. Thus, echo $_SERVER['REQUEST_URI'] and $_SERVER['REDIRECT_URL'] are both empty.

    Once I change it to:
    ErrorDocument 404 /mydomain/myphp.php

    then everything works perfectly.

    Thanks for the help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width