1

I'm still trying to grasp the concept of Apache's RewriteRule, so please confirm if my understanding of the below is correct...

So, here's a snippet of a website's .htaccess, I add numbers in front to ease referencing:

   (1) RewriteRule ^api/rest api.php?type=rest [QSA,L]
   (2) RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

   (3) RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
   (4) RewriteRule .* - [L,R=405]

   (5) RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
   (6) RewriteCond %{REQUEST_FILENAME} !-f
   (7) RewriteCond %{REQUEST_FILENAME} !-d
   (8) RewriteCond %{REQUEST_FILENAME} !-l
   (9) RewriteRule .* index.php [L]

Now, my questions:

  1. Doesn't rule #2 cause premature ending of Rewrite processing, because the "-" stops the iteration?

  2. Cond #5~#9 are applied with 'and' logic, so rule #9 triggers only for "non-existing file/dir/links not within the /(media|skin|js)/ directories. Am I correct?

Thanks in advance!

2

For Q1, the - doesn't mean that processing or iteration would be stopped, simply that the URL path would be passed through without any filtering or processing. The file will continue to execute rules until it reaches the end of the file or a rule is met that has the [L] last rule flag appended to it.

To clarify then, RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] would actually do no URL rewriting or rule matching but simply assign the contents of the HTTP header Authorization into an environment variable named HTTP_AUTHORIZATION.

Yes to Q2 - definately correct.

I may well be wrong here but I've never seen an error message including premature end with relation to the processing of an .htaccess file - normally this kind of error occurs when a server side script (such as your index.php) sends response text such as HTML back to the client web-browser and then tries to send some additional HTTP headers afterwards. All headers must always be sent before any content is sent.

You can read more about htaccess syntax or see examples on the Apache website.

| improve this answer | |
  • Well, there was no "premature end" error message; just my own term to denote that "processing ends here, the next rules are useless". But from your answer, apparently the next rules aren't useless. Thanks! – pepoluan Oct 21 '14 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.