Jump to content

Maintain URL if there is no page


websitings

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.