How do you get absolute or rawurl?

Topics: Developer Forum, User Forum
Apr 7, 2010 at 2:43 PM
Edited Apr 7, 2010 at 2:44 PM

I am using version 2.x of the rewrite filter.

I'm successfully rewriting URLs, so that /foobar/articles.aspx?id=1  gets rewritten as /articles/1/

The problem is that on the backend, I want to assign the rewritten URL to Google Analytics.  To do this, I've tried retrieving using the 


But that doesn't work.  What that gives me is the /foobar/articles.aspx?id=1 URL, not the rewritten URL.

How can I dynamically retrieve the post-rewritten URL?  Request.RawUrl also doesn't work.


Apr 7, 2010 at 3:13 PM

I think you want the pre-rewritten URL.  The URL exposed to the outside world.   Before rewrites.

I think you have your terminology reversed.  When you say "URL gets rewritten to X", it means the external (pretty) URL gets rewritten to the internal (ugly) form.  So, /articles/1 gets rewritten to /foobar/articles.aspx?id=1 .   You had it reversed.

You can get the original by applying the [U] modifier to the RewriteRule that fires.  Then, in your server, retrieve the original URL via the HTTP_X_REWRITE_URL server variable.  In your case the value will be /articles/1 .

Note: The documentation is incorrect regarding the behavior of the U modifier flag.  I'll get that fixed.  Also in v2.1, you will get spurious warnings in the log file when you use the U flag - ignore them.  I'll fix that, too.


Apr 7, 2010 at 3:15 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 7, 2010 at 3:44 PM

Thanks, Cheeso, you're right --had the explanation reversed.  Sorry for any confusion and thanks for the variable explanation.  Seems to work fine.

Apr 7, 2010 at 4:15 PM


FYI, I posted v2.1.1.7 with the fixes I described here - the spurious warning is now gone and the documentation is corrected.

Apr 9, 2010 at 8:35 PM

Cheeso, I think I had mentioned this buried in another post, so we probably dismissed it, but it's directly related to this.

It does seem that this scenario (needing access to the pre-rewritten URL), is a very commonly required scenario.  Would it make sense to have an option (global *and/or* local) to populate HTTP_X_REWRITE_URL automatically with the original url?  Something like "StoreOriginalURL ON|OFF" ?  I'd even suggest defaulting it to "ON". This would

a) provide a really simple way of providing the pre-written URL

b) allow a simple way to use access the pre-written URL without disabling Kernel caching (which the U flag disables)

I suspect this option would get utilized a lot because Apache provides a pre-populated server var for this (REQUEST_URI), and many folks are trying to duplicate Apache functionality.


Apr 9, 2010 at 9:18 PM
Edited Apr 9, 2010 at 9:22 PM

Ah, an interesting idea. It sounds useful.  Easy to document and easy to use.  

It will never be "compatible" with Apache because there's no way to set an environment variable (that I can see) in an IIS6 ISAPI, except for doing so via the request header, which means the HTTP_ prefix will always be present on it.   I'll need to research that further to be absolutely sure.

One thing - the "U" flag doesn't, in fact, cause the kernel caching to be turned off.  the documentation was out of date on that part.  this was true in v1.2 of the filter, but hasn't been true in the v2.0 filter, ever.  The v2.0 documentation was just wrong on that.  As I noted up above, I fixed the documentation in v2.1.1.7. 

EDIT: Actually now that I think back, the only reason this wasn't the default behavior is because of the kernel caching issue, and a sort of wrongheaded coupling on my part between retaining the original URL for access by the application and Logging the original URL.   The latter will cause the kernel cache issue, the former will not.

Apr 9, 2010 at 9:19 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.