Forum Moderators: phranque

Message Too Old, No Replies

THE REQUEST vs REQUEST URI

         

killahbeez

2:19 pm on Aug 13, 2008 (gmt 0)

10+ Year Member



why and when should be use THE_REQUEST instead of REQUEST_URI.

I mean what is the advantage of using
RewriteCond %{THE_REQUEST} /blabla.html\ HTTP/
and not directly
RewriteCond %{REQUEST_URI} /blabla.html

jdMorgan

5:28 pm on Aug 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Standing alone as shown above, there is no "advantage" per se.

There is a difference, though, in the meaning of the two variables: THE_REQUEST is the exact request header as originally received from the client. It is not 'updated' by any internal rewrites (e.g. mod_rewrite, mod_dir, mod_speling, etc.).

REQUEST_URI is basically the same thing as the URL-path 'seen' by RewriteRule. It *is* updated by any internal rewrites that occur previous to the RewriteRule or RewriteCond referencing it.

So, the two variables contain different information:

THE_REQUEST: GET /page.php?name1=value1&name2=value2 HTTP/1.1
REQUEST_URI: /page.php

THE_REQUEST is quite useful for testing for un-decoded characters, blank query strings ("?" followed by nothing), checking the requested URL *and* the query string (and possibly the HTTP method and protocol version as well) all together in one operation, and in determining if the REQUEST_URI/RewriteRule URL has already been rewritten within the context of the current HTTP request.

This latter function is critical in preventing loops when rewriting friendly URLs to internal script filepaths and at the same time trying to redirect old unfriendly URLs to the new friendly ones. This is impossible without using THE_REQUEST.

Jim

killahbeez

5:41 am on Aug 14, 2008 (gmt 0)

10+ Year Member



Thank you very much for the explanation