1

For my error documents, I am using a single error page (error.html), which I redirect to using

ErrorDocument xxx http://www.example.com/error.html?error=xxx

This works fine, and I do the same for each of the 4xx and 5xx error codes, with the 'error=xxx' query string actually defining how the page looks (in terms of what text to display for what error was encountered).

I also need to capture the URL that was entered before the ErrorDocument redirect takes place, and append this to the ErrorDocument location as another query string

ErrorDocument xxx http://www.example.com/error.html?error=xxx**&url=yyy**

Am I able to do this? I know I read somewhere that it was possible with PHP, but I am avoiding PHP for this site (and it actually didn't work as expected when I did try).

I have looked at similar questions, but could not find one with that aided me.

1 Answer 1

1

Remove http:// from ErrorDocument to avoid redirection for error condition like this:

ErrorDocument 404 /error.html?error=404
ErrorDocument 500 /error.html?error=500
...

This way entered URI is available as REQUEST_URI in your error.html since browser URI won't change.

Sign up to request clarification or add additional context in comments.

6 Comments

Will I still be able to access my query string for the page error doing it like this? This was the reason that I changed it to actually redirect in the first place...
Using the code from stackoverflow.com/questions/901115/… and stackoverflow.com/a/16366232/1055122 both do not work without the redirect.
I am using similar rule myself. Only difference is that I am using a .php which is far easier than parsing query string in Javascript. My rule looks like: ErrorDocument 404 /error.php?error=404
Thank you. I tweaked my code and implemented the PHP script as I previously had, and it worked this time, although the query in the ErrorDocument of .htaccess did not.
Hi, doing it this way (redirecting to my html page) did not work. I had it direct to a PHP script, which captured the query and target URL, before redirecting to the error page. I just couldn't capture the query from my html page directly without a full direct, so I implemented the script.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.