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.

Andre C
  • 457
  • 1
  • 9
  • 26

1 Answers1

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 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... – Andre C Dec 08 '13 at 08:21
  • Using the code from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144 and http://stackoverflow.com/a/16366232/1055122 both do not work without the redirect. – Andre C Dec 08 '13 at 08:36
  • 1
    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` – anubhava Dec 08 '13 at 08:56
  • 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. – Andre C Dec 09 '13 at 06:18
  • Great to know it worked out. Let me know by example what didn't work for you? – anubhava Dec 09 '13 at 07:53
  • 1
    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. – Andre C Dec 09 '13 at 08:12