Jump to content


This topic is now archived and is closed to further replies.


Maintain URL if there is no page

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.