Forum Moderators: phranque

Message Too Old, No Replies

REQUEST URI vs THE REQUEST

         

jason928

2:15 am on May 18, 2009 (gmt 0)

10+ Year Member



Hi,

I was trying to create a RewriteRule to prevent redirection from a directory, because the directory were password protected. I created a rule like this:

RewriteCond %{REQUEST_URI} ^/mydirectory
RewriteRule (.*) - [L]
#... rest for redirect rules

So I suppose if I request
http:// mydomain.com / mydirectory

The HTTP variable REQUEST_URI should be set to
/mydirectory

However it does not seem to work. I looked at my HTTP header from my firefox plugin, the header has the content similar to this:

GET mydirectory/ HTTP/1.1

So i change my rule to:
RewriteCond %{THE_REQUEST} ^(GET¦POST)\s/worship [NC]
RewriteRule (.*) - [L]

And now this works just fine.

But I still don't understand what was wrong in the first syntax. Isn't the REQUEST_URI always set to the path after GET or POST int THE_REQUEST variable?

Thanks in advance,
Jason

jdMorgan

3:09 am on May 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your first rule should have worked, as should the simpler, single-line rule:
RewriteRule ^mydirectory - [L]

unless the requested URL has been rewritten or aliased by another rule.

Basically, THE_REQUEST is the entire request line received from the client (e.g. browser or search engine robot), and is unaffected by internal rewrites or anything else; It is what the client sent to start this HTTP transaction.

So you might want to look at all the code in your .htaccess files, and make sure that no other rules might have been applied to requests for /mydirectory URL-paths, changing them before the first rule you posted gets evaluated.

Jim

jason928

4:50 am on May 18, 2009 (gmt 0)

10+ Year Member



Thanks! Unfortunately the 1-line version still does not work. Since I am using shared hosting, I cannot see the rules in http.conf. Possibly it was altered.

I thought the URL was changed for the PATTERN matching in RewriteRule, and i did not realized that it could be change in %{REQUEST_URI} for RewriteCond.

If I were able to see the rewrite log, I can solve this puzzle. But again I am not allowed because of shared hosting.

Anyway thanks again. I learn something today!

Thanks,
Jason