Jump to content


Photo

Maintain URL if there is no page


  • Please log in to reply
2 replies to this topic

#1 websitings

websitings
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 May 2006 - 11:47 AM

I am seeking guidance for the following challenge.

If someone visits my website using a non existant page url or may just have typed incorrectly in the browser location.

For example they may have typed:

[a href=\"http://www.mydomain.com/a/nonexistant\" target=\"_blank\"]http://www.mydomain.com/a/nonexistant[/a]

I would like the browser to maintain what they have typed in the address box but I would like to display a page which can handle a php script to display a message based on what they entered for the url.

I would have no problem writing the script to display the message but I am struggling on working out how to maintain the url which is important to me. I can work out how to use htaccess for a 404 redirect but that's not what I want

I assume it would be using some 404 handler but can't work it out myself. Any help greatly appreciated.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 08 May 2006 - 02:03 PM

You will need to have access to the 404 handler provided by your server. Normally this is like 404.shtml or something similar. You will have to overwrite this file with whatever comments your users need to see. You should be able to catch the URL and then redirect or whatever you need to do.

Info: PHP Manual


#3 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 08 May 2006 - 04:13 PM

you can actually do this with htaccess aswell (least on my host's server setup),
i have something similar to this in my .htaccess (note: NOT full url):

ErrorDocument 404 /index.php?page=404_error
ErrorDocument 403 /index.php?page=403_error

and in index i use switch to load the 403/404 pages i made. When i hit for example www.mydomain.no/jhgfaqgfa - the htaccess loads the index switch while the url still is the same as when mistyped - no change.

by using $_SERVER['REQUEST_URI'] in your 403/404 document, you can split and use whatever is in the adress bar.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users