Detect the original URL before the rewrite rule applied in code


I’d like to setup a rewrite rule, but we also want to update the canonical URL for analytics to reflect the updated rewrite rule for Google.

Is it possible to detect that rewrite rule was applied from the HTTP headers and see the original url before the rewrite applied?