3

Does anyone knows when IS_SUBREQ variable is "true"? Everything, that i've tried, gave me only "false".

Info from apache docs

IS_SUBREQ Will contain the text "true" if the request currently being processed is a sub-request, "false" otherwise. Sub-requests may be generated by modules that need to resolve additional files or URIs in order to complete their tasks.

Could anyone show me some example when IS_SUBREQ is "true"?

Some of what i tried: subreq.php - page with only

Testing browser's subrequest for image (I know that server doesn't care about it, but tried)

RewriteCond %{IS_SUBREQ} true
RewriteRule (.*)\.png$ null

Testing internal redirects

RewriteRule subreq\.php$ \tmp
RewriteCond %{IS_SUBREQ} true
RewriteRule tmp$ /index.html

No effect.

4

1 回答 1

1

As per Apache Manual subrequest is:

a page which is included using an SSI (Server Side Include) is a subrequest, and you may want to avoid rewrites happening on those subrequests. Also, when mod_dir tries to find out information about possible directory default files (such as index.html files), this is an internal subrequest, and you often want to avoid rewrites on such subrequests

So to get value of %{IS_SUBREQ}=true have a RewriteRule like this:

DirectoryIndex index.php

RewriteEngine On

RewriteCond %{IS_SUBREQ} true
RewriteRule ^index\.php$ $0?s=%{IS_SUBREQ} [L]
  • Then visit your website by opening this URL: http://site.com/
  • Then inside /index.php if you dump $_GET['s'] you will see value true.
于 2013-10-11T15:28:38.447 回答