www.webdeveloper.com
Results 1 to 2 of 2

Thread: Get Page URL For 404

  1. #1
    Join Date
    Mar 2010
    Posts
    672

    Get Page URL For 404

    Is there a way to get the URL for a page that gave a 404 error? I'm trying to make a 404 page that searches the url for words which i can use to redirect them to a more appropriate page (pretty easy considering the category and product names are in the url). I've been able to get the referrer, but having the actual url itself that threw the 404 is what i need.
    Anyone have any ideas?
    Thanks!

  2. #2
    Join Date
    May 2010
    Location
    New Jersey
    Posts
    16
    Sure - depending on your web server software you can set the default 404 page, and direct all 404s to a PHP script that can parse the URL and send people where you want them to.

    I would suggest adding an .htaccess file with the following (or adding this to your existing one):

    Code:
    ErrorDocument 404 /redirect.php
    and then creating a redirect.php that parses the URL (perhaps using $_SERVER['SCRIPT_NAME']) and redirects the user to the appropriate location.

    Quote Originally Posted by Jarrod1937 View Post
    Is there a way to get the URL for a page that gave a 404 error? I'm trying to make a 404 page that searches the url for words which i can use to redirect them to a more appropriate page (pretty easy considering the category and product names are in the url). I've been able to get the referrer, but having the actual url itself that threw the 404 is what i need.
    Anyone have any ideas?
    Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles